Home Explore Blog CI



neovim

3rd chunk of `runtime/doc/usr_40.txt`
5fad58fc3a1ede155b198ad76340a715f7aaa169bda0f7040000000100000fa1
 are now editing the
first file.  Define this mapping: >

	:map ,, :s/5.1/5.2/<CR>:wnext<CR>,,

Now you type ",,".  This triggers the mapping.  It replaces "5.1" with "5.2"
in the first line.  Then it does a ":wnext" to write the file and edit the
next one.  The mapping ends in ",,".  This triggers the same mapping again,
thus doing the substitution, etc.
   This continues until there is an error.  In this case it could be a file
where the substitute command doesn't find a match for "5.1".  You can then
make a change to insert "5.1" and continue by typing ",," again.  Or the
":wnext" fails, because you are in the last file in the list.
   When a mapping runs into an error halfway, the rest of the mapping is
discarded.  CTRL-C interrupts the mapping (CTRL-Break on MS-Windows).


DELETE A MAPPING

To remove a mapping use the ":unmap" command.  Again, the mode the unmapping
applies to depends on the command used:

	:unmap		Normal, Visual and Operator-pending
	:vunmap		Visual
	:nunmap		Normal
	:ounmap		Operator-pending
	:unmap!		Insert and Command-line
	:iunmap		Insert
	:cunmap		Command-line

There is a trick to define a mapping that works in Normal and Operator-pending
mode, but not in Visual mode.  First define it for all three modes, then
delete it for Visual mode: >

	:map <C-A> /---><CR>
	:vunmap <C-A>

Notice that the five characters "<C-A>" stand for the single key CTRL-A.

To remove all mappings use the |:mapclear| command.  You can guess the
variations for different modes by now.  Be careful with this command, it can't
be undone.


SPECIAL CHARACTERS

The ":map" command can be followed by another command.  A | character
separates the two commands.  This also means that a | character can't be used
inside a map command.  To include one, use <Bar> (five characters).  Example:
>
	:map <F8> :write <Bar> !checkin %:S<CR>

The same problem applies to the ":unmap" command, with the addition that you
have to watch out for trailing white space.  These two commands are different:
>
	:unmap a | unmap b
	:unmap a| unmap b

The first command tries to unmap "a ", with a trailing space.

When using a space inside a mapping, use <Space> (seven characters): >

	:map <Space> W

This makes the spacebar move a blank-separated word forward.

It is not possible to put a comment directly after a mapping, because the "
character is considered to be part of the mapping.  You can use `|"`, this
starts a new, empty command with a comment.  Example: >

	:map <Space> W|     " Use spacebar to move forward a word


MAPPINGS AND ABBREVIATIONS

Abbreviations are a lot like Insert mode mappings.  The arguments are handled
in the same way.  The main difference is the way they are triggered.  An
abbreviation is triggered by typing a non-word character after the word.  A
mapping is triggered when typing the last character.
   Another difference is that the characters you type for an abbreviation are
inserted in the text while you type them.  When the abbreviation is triggered
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

Title: Deleting Mappings, Special Characters, and Mapping vs. Abbreviations in Vim
Summary
This section covers deleting mappings using `:unmap` for different modes and provides a trick to define mappings that work in Normal and Operator-pending modes but not in Visual mode. It also explains how to use special characters like `<Bar>` for the `|` character and `<Space>` for spaces within mappings. The section distinguishes mappings from abbreviations, highlighting differences in how they are triggered and handled during typing. It also notes the use of `<script>` and `<buffer>` keywords.