Home Explore Blog CI



neovim

17th chunk of `runtime/doc/map.txt`
ebeba5c5aadc673cebdeb14f8506e0f9f5fb0dc62991dc710000000100000fa4
 the second,
	and fourth ^Vs, and the ^[, to be entered into the command-line.

You see:    ab esc ^V^V^[

	The command-line contains two actual ^Vs before the ^[.  This is
	how it should appear in your vimrc file, if you choose to go that
	route.  The first ^V is there to quote the second ^V; the :ab
	command uses ^V as its own quote character, so you can include quoted
	whitespace or the | character in the abbreviation.  The :ab command
	doesn't do anything special with the ^[ character, so it doesn't need
	to be quoted.  (Although quoting isn't harmful; that's why typing 7
	[but not 8!] ^Vs works.)

Stored as:  esc     ^V^[

	After parsing, the abbreviation's short form ("esc") and long form
	(the two characters "^V^[") are stored in the abbreviation table.
	If you give the :ab command with no arguments, this is how the
	abbreviation will be displayed.

	Later, when the abbreviation is expanded because the user typed in
	the word "esc", the long form is subjected to the same type of
	^V interpretation as keyboard input.  So the ^V protects the ^[
	character from being interpreted as the "exit Insert mode" character.
	Instead, the ^[ is inserted into the text.

Expands to: ^[

[example given by Steve Kirkendall]

==============================================================================
3. Local mappings and functions				*script-local*

When using several Vim script files, there is the danger that mappings and
functions used in one script use the same name as in other scripts.  To avoid
this, they can be made local to the script.

						*<SID>* *<SNR>* *E81*
The string "<SID>" can be used in a mapping or menu.  This is useful if you
have a script-local function that you want to call from a mapping in the same
script.
   When executing the map command, Vim will replace "<SID>" with the special
key code <SNR>, followed by a number that's unique for the script, and an
underscore.  Example: >
	:map <SID>Add
would define a mapping "<SNR>23_Add".

When defining a function in a script, "s:" can be prepended to the name to
make it local to the script.  But when a mapping is executed from outside of
the script, it doesn't know in which script the function was defined.  To
avoid this problem, use "<SID>" instead of "s:".  The same translation is done
as for mappings.  This makes it possible to define a call to the function in
a mapping.

When a local function is executed, it runs in the context of the script it was
defined in.  This means that new functions and mappings it defines can also
use "s:" or "<SID>" and it will use the same unique number as when the
function itself was defined.  Also, the "s:var" local script variables can be
used.

When executing an autocommand or a user command, it will run in the context of
the script it was defined in.  This makes it possible that the command calls a
local function or uses a local mapping.

In case the value is used in a context where <SID> cannot be correctly
expanded, use the expand() function: >
	let &includexpr = expand('<SID>') .. 'My_includeexpr()'

Otherwise, using "<SID>" outside of a script context is an error.

If you need to get the script number to use in a complicated script, you can
use this function: >
	func s:ScriptNumber()
	  return matchstr(expand('<SID>'), '<SNR>\zs\d\+\ze_')
	endfunc

The "<SNR>" will be shown when listing functions and mappings.  This is useful
to find out what they are defined to.

The |:scriptnames| command can be used to see which scripts have been sourced
and what their <SNR> number is.

==============================================================================
4. User-defined commands				*user-commands*

It is possible to define your own Ex commands.  A user-defined command can act
just like a built-in command (it can have a range or arguments, arguments can
be completed as filenames or buffer names, etc), except that when the command
is executed, it is transformed into a normal Ex command and then executed.

For starters: See section |40.2|

Title: CTRL-V Interpretation and Script-Local Mappings/Functions
Summary
This section describes how CTRL-V is used to escape special characters in abbreviations, ensuring they are interpreted correctly. It also covers the concept of script-local mappings and functions using "<SID>", which Vim replaces with a unique script number to avoid naming conflicts between scripts. It elaborates on defining and calling script-local functions from mappings, autocommands, and user commands, as well as how to get the script number. Additionally, it introduces user-defined commands and their basic functionalities.