Home Explore Blog CI



neovim

31th chunk of `runtime/doc/vimeval.txt`
d4abaea2b400ce18f7103b47c2869679fba60f338b0fa5520000000100000fa0

			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 work, because when commands are skipped the
			":execute" is not evaluated and Vim loses track of
			where blocks start and end.  Also "break" and
			"continue" should not be inside ":execute".
			This example does not work, because the ":execute" is
			not evaluated and Vim does not see the "while", and
			gives an error for finding an ":endwhile": >
		:if 0
		: execute 'while i > 5'
		:  echo "test"
		: endwhile
		:endif
<
			It is allowed to have a "while" or "if" command
			completely in the executed string: >
		:execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
<

							*:exe-comment*
			":execute", ":echo" and ":echon" cannot be followed by
			a comment directly, because they see the '"' as the
			start of a string.  But, you can use '|' followed by a
			comment.  Example: >
		:echo "foo" | "this is a comment

==============================================================================
8. Exception handling					*exception-handling*

The Vim script language comprises an exception handling feature.  This section
explains how it can be used in a Vim script.

Exceptions may be raised by Vim on an error or on interrupt, see
|catch-errors| and |catch-interrupt|.  You can also explicitly throw an
exception by using the ":throw" command, see |throw-catch|.


TRY CONDITIONALS					*try-conditionals*

Exceptions can be caught or can cause cleanup code to be executed.  You can
use a try conditional to specify catch clauses (that catch exceptions) and/or
a finally clause (to be executed for cleanup).
   A try conditional begins with a |:try| command and ends at the matching
|:endtry| command.  In between, you can use a |:catch| command to start
a catch clause, or a |:finally| command to start a finally clause.  There may
be none or multiple catch clauses, but there is at most one finally clause,
which must not be followed by any catch clauses.  The lines before the catch
clauses and the finally clause is called a try block. >

     :try
     :	...
     :	...				TRY BLOCK
     :	...
     :catch /{pattern}/
     :	...
     :	...				CATCH CLAUSE
     :	...
     :catch /{pattern}/
     :	...
     :	...				CATCH CLAUSE
     :	...
     :finally
     :	...
     :	...				FINALLY CLAUSE
     :	...
     :endtry

The try conditional allows to watch code for exceptions and to take the
appropriate actions.  Exceptions from the try block may be caught.  Exceptions
from the try block and also the catch clauses may cause cleanup actions.
   When no exception is thrown during execution of the try block, the control
is transferred to the finally clause, if present.  After its execution, the
script continues with the line following the ":endtry".
   When an exception occurs during execution of the try block, the remaining
lines in the try block are skipped.  The exception is matched against the
patterns specified as arguments to the ":catch" commands.  The catch clause
after the first matching ":catch" is taken, other catch clauses are not
executed.  The catch

Title: Vim Script: Execute Command Details and Exception Handling
Summary
This section continues the discussion of the `:execute` command, emphasizing limitations with 'if', 'while', and 'for' commands within executed strings. It clarifies that comments cannot directly follow `:execute`, `:echo`, or `:echon` commands. Additionally, the section introduces exception handling in Vim scripts, covering `try-conditionals`. It outlines the structure of a `try` block, `catch` clauses, and a `finally` clause, detailing how exceptions are caught and how cleanup code is executed, as well as the flow of control when exceptions occur or do not occur.