On vim
, command-mode keys can be mapped through the ex
command :map <key> <macro>
and insert-mode keys can be mapped through :map! <key> <macro>
. After mapped, the commands to remove the mapping from the command-mode keys and insert-mode keys are unmap <key>
and unmap! <key>
respectively.
This works well with command-mode keys, but with insert-mode keys the key expansion also works on the ex
command line prompt: trying to type the key end up in the macro expansion taking place resulting in bad argument to the unmap!
command (E474: Invalid Argument
) or maybe the command might try to unmap some different key from the one intended (E31: No such mapping
).
How can someone correctly remove a insert-mode mapped key on vim
?
While mapping a key, CTRL+V
can be used to escape some special characters like ENTER
, ESC
or some particular control keys.
The same applies when using mapped insert-mode keys: they can be escaped when preceded by CTRL+V
both while editing the text and while writing commands to the ex
command-line prompt.
If for example, the +
insert-key is mapped to some macro and the user wants to unmap it, the key must be escaped while writing the ex
command to avoid the macro expansion:
:unmap!
+ CTRL+V
(shows a ^
) + <key>
The same can be done if a regular +
is needed in the text while editing it in insert-mode.