Home Explore Blog CI



neovim

24th chunk of `runtime/doc/vimeval.txt`
37334f4577a294a773916a196a978bd11adc660212e57d2c0000000100000fa4
 {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
			expression evaluation fails, then the assignment fails.

			{endmarker} must not contain white space.
			{endmarker} cannot start with a lower case character.
			The last line should end only with the {endmarker}
			string without any other character.  Watch out for
			white space after {endmarker}!

			Without "trim" any white space characters in the lines
			of text are preserved.  If "trim" is specified before
			{endmarker}, then indentation is stripped so you can
			do: >
				let text =<< trim END
				   if ok
				     echo 'done'
				   endif
				END
<			Results in: `["if ok", "  echo 'done'", "endif"]`
			The marker must line up with "let" and the indentation
			of the first line is removed from all the text lines.
			Specifically: all the leading indentation exactly
			matching the leading indentation of the first
			non-empty text line is stripped from the input lines.
			All leading indentation exactly matching the leading
			indentation before `let` is stripped from the line
			containing {endmarker}.  Note that the difference
			between space and tab matters here.

			If {var-name} didn't exist yet, it is created.
			Cannot be followed by another command, but can be
			followed by a comment.

			To avoid line continuation to be applied, consider
			adding 'C' to 'cpoptions': >
				set cpo+=C
				let var =<< END
				   \ leading backslash
				END
				set cpo-=C
<
			Examples: >
				let var1 =<< END
				Sample text 1
				    Sample text 2
				Sample text 3
				END

				let data =<< trim DATA
					1 2 3 4
					5 6 7 8
				DATA

				let code =<< trim eval CODE
				   let v = {10 + 20}
				   let h = "{$HOME}"
				   let s = "{Str1()} abc {Str2()}"
				   let n = {MyFunc(3, 4)}
				CODE
<
								*E121*
:let {var-name}	..	List the value of variable {var-name}.  Multiple
			variable names may be given.  Special names recognized
			here:				*E738*
			  g:	global variables
			  b:	local buffer variables
			  w:	local window variables
			  t:	local tab page variables
			  s:	script-local variables
			  l:	local function variables
			  v:	Vim variables.

:let			List the values of all variables.  The type of the
			variable is indicated before the value:
			    <nothing>	String
				#	Number
				*	Funcref


:unl[et][!] {name} ...				*:unlet* *:unl* *E108* *E795*
			Remove the internal variable {name}.  Several variable
			names can be given, they are all removed.  The name
			may also be a |List| or |Dictionary| item.
			With [!] no error message is given for non-existing
			variables.
			One or more items from a |List| can be removed: >
				:unlet list[3]	  " remove fourth item
				:unlet list[3:]   " remove fourth item to last
<			One item from a |Dictionary| can be removed at a time: >
				:unlet dict['two']
				:unlet dict.two
<			This is especially useful to clean up used global
			variables and script-local variables (these are not
			deleted when the script ends).  Function-local
			variables are automatically deleted when the function

Title: Vim Script: :let Heredoc and :unlet
Summary
This section describes the ':let=<<' command (heredoc) which allows assigning a multi-line string or evaluated expression to a variable. The 'trim' option removes indentation, while 'eval' enables the evaluation of Vim expressions within the text. It also describes :let's ability to list all variables. Furthermore, the ':unlet' command is introduced for removing internal variables, including items from Lists or Dictionaries, with an option to suppress errors for non-existing variables.