Home Explore Blog CI



neovim

23th chunk of `runtime/doc/vimeval.txt`
81cf582b9ed3228206d4892ae9afa60e9f2a95d7e9f69f640000000100000fa0
 register
			{reg-name}.  {reg-name} must be a single letter, and
			must be the name of a writable register (see
			|registers|).  "@@" can be used for the unnamed
			register, "@/" for the search pattern.
			If the result of {expr1} ends in a <CR> or <NL>, the
			register will be linewise, otherwise it will be set to
			charwise.
			This can be used to clear the last search pattern: >
				:let @/ = ""
<			This is different from searching for an empty string,
			that would match everywhere.

:let @{reg-name} .= {expr1}
			Append {expr1} to register {reg-name}.  If the
			register was empty it's like setting it to {expr1}.

:let &{option-name} = {expr1}			*:let-option* *:let-&*
			Set option {option-name} to the result of the
			expression {expr1}.  A String or Number value is
			always converted to the type of the option.
			For an option local to a window or buffer the effect
			is just like using the |:set| command: both the local
			value and the global value are changed.
			Example: >
				:let &path = &path .. ',/usr/local/include'

:let &{option-name} .= {expr1}
			For a string option: Append {expr1} to the value.
			Does not insert a comma like |:set+=|.

:let &{option-name} += {expr1}
:let &{option-name} -= {expr1}
			For a number or boolean option: Add or subtract
			{expr1}.

:let &l:{option-name} = {expr1}
:let &l:{option-name} .= {expr1}
:let &l:{option-name} += {expr1}
:let &l:{option-name} -= {expr1}
			Like above, but only set the local value of an option
			(if there is one).  Works like |:setlocal|.

:let &g:{option-name} = {expr1}
:let &g:{option-name} .= {expr1}
:let &g:{option-name} += {expr1}
:let &g:{option-name} -= {expr1}
			Like above, but only set the global value of an option
			(if there is one).  Works like |:setglobal|.

:let [{name1}, {name2}, ...] = {expr1}		*:let-unpack* *E687* *E688*
			{expr1} must evaluate to a |List|.  The first item in
			the list is assigned to {name1}, the second item to
			{name2}, etc.
			The number of names must match the number of items in
			the |List|.
			Each name can be one of the items of the ":let"
			command as mentioned above.
			Example: >
				:let [s, item] = GetItem(s)
<			Detail: {expr1} is evaluated first, then the
			assignments are done in sequence.  This matters if
			{name2} depends on {name1}.  Example: >
				:let x = [0, 1]
				:let i = 0
				:let [i, x[i]] = [1, 2]
				:echo x
<			The result is [0, 2].

:let [{name1}, {name2}, ...] .= {expr1}
:let [{name1}, {name2}, ...] += {expr1}
:let [{name1}, {name2}, ...] -= {expr1}
			Like above, but append/add/subtract the value for each
			|List| item.

:let [{name}, ..., ; {lastname}] = {expr1}				*E452*
			Like |:let-unpack| above, but the |List| may have more
			items than there are names.  A list of the remaining
			items is assigned to {lastname}.  If there are no
			remaining items {lastname} is set to an empty list.
			Example: >
				:let [a, b; rest] = ["aval", "bval", 3, 4]
<
:let [{name}, ..., ; {lastname}] .= {expr1}
:let [{name}, ..., ; {lastname}] += {expr1}
:let [{name}, ..., ; {lastname}] -= {expr1}
			Like above, but append/add/subtract the value for each
			|List| item.

						*:let=<<* *:let-heredoc*
					*E990* *E991* *E172* *E221* *E1145*
:let {var-name} =<< [trim] [eval] {endmarker}
text...
text...
{endmarker}
			Set internal variable {var-name} to a |List|
			containing the lines of text bounded by the string
			{endmarker}.

			If "eval" is not specified, then each line of text is
			used as a |literal-string|, except that single quotes
			does not need to be doubled.
			If "eval" is specified, then any Vim expression in the
			form {expr} is evaluated and the result replaces the
			expression, like with |interpolated-string|.
			Example where $HOME is expanded: >
				let lines =<< trim eval END
				  some text
				  See the file {$HOME}/.vimrc
				  more text
				END
<			There can be multiple Vim expressions in a single line
			but an expression cannot span multiple lines.  If any
	

Title: Vim Script: More ':let' Command Examples, including option setting and list unpacking
Summary
This section provides further examples of the ':let' command, focusing on its use with registers and options. It details how to set both local and global option values, append to string options, and perform arithmetic operations on numerical or boolean options. It introduces list unpacking with ':let', enabling the assignment of multiple variables from a list. The section also explains how to handle lists with more items than variables and introduces ':let-heredoc' for setting variables to multiline text blocks with optional expression evaluation.