Home Explore Blog CI



neovim

4th chunk of `runtime/doc/usr_40.txt`
8ead469384cecf89ce3178a87623188e1d3f494d310d86f90000000100000fa0

these characters are deleted and replaced by what the abbreviation produces.
When typing the characters for a mapping, nothing is inserted until you type
the last character that triggers it.  If the 'showcmd' option is set, the
typed characters are displayed in the last line of the Vim window.
   An exception is when a mapping is ambiguous.  Suppose you have done two
mappings: >

	:imap aa foo
	:imap aaa bar

Now, when you type "aa", Vim doesn't know if it should apply the first or the
second mapping.  It waits for another character to be typed.  If it is an "a",
the second mapping is applied and results in "bar".  If it is a space, for
example, the first mapping is applied, resulting in "foo", and then the space
is inserted.


ADDITIONALLY...

The <script> keyword can be used to make a mapping local to a script.  See
|:map-<script>|.

The <buffer> keyword can be used to make a mapping local to a specific buffer.
See |:map-<buffer>|

The <unique> keyword can be used to make defining a new mapping fail when it
already exists.  Otherwise a new mapping simply overwrites the old one.  See
|:map-<unique>|.

To make a key do nothing, map it to <Nop> (five characters).  This will make
the <F7> key do nothing at all: >

	:map <F7> <Nop>| map! <F7> <Nop>

There must be no space after <Nop>.

==============================================================================
*40.2*	Defining command-line commands

The Vim editor enables you to define your own commands.  You execute these
commands just like any other Command-line mode command.
   To define a command, use the ":command" command, as follows: >

	:command DeleteFirst 1delete

Now when you execute the command ":DeleteFirst" Vim executes ":1delete", which
deletes the first line.

	Note:
	User-defined commands must start with a capital letter.  You cannot
	use ":Next".  The underscore cannot be used!  You can use digits, but
	this is discouraged.

To list the user-defined commands, execute the following command: >

	:command

Just like with the builtin commands, the user defined commands can be
abbreviated.  You need to type just enough to distinguish the command from
another.  Command line completion can be used to get the full name.


NUMBER OF ARGUMENTS

User-defined commands can take a series of arguments.  The number of arguments
must be specified by the -nargs option.  For instance, the example
:DeleteFirst command takes no arguments, so you could have defined it as
follows: >

	:command -nargs=0 DeleteFirst 1delete

However, because zero arguments is the default, you do not need to add
"-nargs=0".  The other values of -nargs are as follows:

	-nargs=0	No arguments
	-nargs=1	One argument
	-nargs=*	Any number of arguments
	-nargs=?	Zero or one argument
	-nargs=+	One or more arguments


USING THE ARGUMENTS

Inside the command definition, the arguments are represented by the
<args> keyword.  For example: >

	:command -nargs=+ Say :echo "<args>"

Now when you type >

	:Say Hello World

Vim echoes "Hello World".  However, if you add a double quote, it won't work.
For example: >

	:Say he said "hello"

To get special characters turned into a string, properly escaped to use as an
expression, use "<q-args>": >

	:command -nargs=+ Say :echo <q-args>

Now the above ":Say" command will result in this to be executed: >

	:echo "he said \"hello\""

The <f-args> keyword contains the same information as the <args> keyword,
except in a format suitable for use as function call arguments.  For example:
>
	:command -nargs=* DoIt :call AFunction(<f-args>)
	:DoIt a b c

Executes the following command: >

	:call AFunction("a", "b", "c")


LINE RANGE

Some commands take a range as their argument.  To tell Vim that you are
defining such a command, you need to specify a -range option.  The values for
this option are as follows:

	-range		Range is allowed; default is the current line.
	-range=%	Range is allowed; default is the whole file.
	-range={count}	Range is allowed; the last number in it is used

Title: Vim Mappings and Abbreviations, Defining Command-Line Commands
Summary
This section explains that mappings are not inserted until the last character is typed, while abbreviations are deleted and replaced. It covers the <script>, <buffer>, and <unique> keywords for mappings and how to disable a key using <Nop>. It then explains how to define custom commands in Vim using `:command`, including setting the number of arguments with `-nargs` and using `<args>`, `<q-args>`, and `<f-args>` to access them. Finally, it covers the `-range` option for commands that accept a line range.