Home Explore Blog CI



neovim

30th chunk of `runtime/doc/vimeval.txt`
78624cd3484e9fd5c15e6a8dcb8b62dca3862d5ce01f8f1c0000000100000fa6
 external shell
			command: >
		:!echo %		--> filename
<			The arguments of ":!" are expanded, see |:_%|. >
		:!echo "%"		--> filename or "filename"
<			Like the previous example.  Whether you see the double
			quotes or not depends on your 'shell'. >
		:echo %			--> nothing
<			The '%' is an illegal character in an expression. >
		:echo "%"		--> %
<			This just echoes the '%' character. >
		:echo expand("%")	--> filename
<			This calls the expand() function to expand the '%'.

							*:echoh* *:echohl*
:echoh[l] {name}	Use the highlight group {name} for the following
			`:echo`, `:echon` and `:echomsg` commands.  Also used
			for the `input()` prompt.  Example: >
		:echohl WarningMsg | echo "Don't panic!" | echohl None
<			Don't forget to set the group back to "None",
			otherwise all following echo's will be highlighted.

							*:echom* *:echomsg*
:echom[sg] {expr1} ..	Echo the expression(s) as a true message, saving the
			message in the |message-history|.
			Spaces are placed between the arguments as with the
			`:echo` command.  But unprintable characters are
			displayed, not interpreted.
			The parsing works slightly different from `:echo`,
			more like `:execute`.  All the expressions are first
			evaluated and concatenated before echoing anything.
			If expressions does not evaluate to a Number or
			String, string() is used to turn it into a string.
			Uses the highlighting set by the `:echohl` command.
			Example: >
		:echomsg "It's a Zizzer Zazzer Zuzz, as you can plainly see."
<			See |:echo-redraw| to avoid the message disappearing
			when the screen is redrawn.
							*:echoe* *:echoerr*
:echoe[rr] {expr1} ..	Echo the expression(s) as an error message, saving the
			message in the |message-history|.  When used in a
			script or function the line number will be added.
			Spaces are placed between the arguments as with the
			`:echomsg` command.  When used inside a try conditional,
			the message is raised as an error exception instead
			(see |try-echoerr|).
			Example: >
		:echoerr "This script just failed!"
<			If you just want a highlighted message use `:echohl`.
			And to get a beep: >
		:exe "normal \<Esc>"
<
							*:eval*
:eval {expr}		Evaluate {expr} and discard the result.  Example: >
				:eval Getlist()->Filter()->append('$')

<			The expression is supposed to have a side effect,
			since the resulting value is not used.  In the example
			the `append()` call appends the List with text to the
			buffer.  This is similar to `:call` but works with any
			expression.

			The command can be shortened to `:ev` or `:eva`, but
			these are hard to recognize and therefore not to be
			used.

			The command cannot be followed by "|" and another
			command, since "|" is seen as part of the expression.


							*:exe* *:execute*
:exe[cute] {expr1} ..	Executes the string that results from the evaluation
			of {expr1} as an Ex command.
			Multiple arguments are concatenated, with a space in
			between.  To avoid the extra space use the ".."
			operator to concatenate strings into one argument.
			{expr1} is used as the processed command, command line
			editing keys are not recognized.
			Cannot be followed by a comment.
			Examples: >
		:execute "buffer" nextbuf
		:execute "normal" count .. "w"
<
			":execute" can be used to append a command to commands
			that don't accept a '|'.  Example: >
		:execute '!ls' | echo "theend"

<			":execute" is also a nice way to avoid having to type
			control characters in a Vim script for a ":normal"
			command: >
		:execute "normal ixxx\<Esc>"
<			This has an <Esc> character, see |expr-string|.

			Be careful to correctly escape special characters in
			file names.  The |fnameescape()| function can be used
			for Vim commands, |shellescape()| for |:!| commands.
			Examples: >
		:execute "e " .. fnameescape(filename)
		:execute "!ls " .. shellescape(filename, 1)
<
			Note: The executed string may be any command-line, but
			starting or ending "if", "while" and "for" does not
			always

Title: Vim Script: Echo Commands and Execute
Summary
This section discusses the nuances between the internal `:echo` command and the external shell `!echo` command. It introduces ':echom' for displaying messages with special character handling and saving to the message history, and ':echoerr' for displaying error messages, which also saves to message history and includes the line number in scripts. It also introduces the ':eval' command to evaluate expressions with side effects. The section then elaborates on the ':execute' command, explaining how it executes strings as Ex commands, its use in concatenating commands, and its application in avoiding control characters in ':normal' commands. It also highlights the importance of escaping special characters in filenames using `fnameescape()` and `shellescape()` when using ':execute'.