What does nore
mean when mapping keys in vim? For example, what is the difference between these two mappings?
:map ddd ddjdd
and
:noremap ddd ddjdd
Introduction. Key mapping refers to creating a shortcut for repeating a sequence of keys or commands. You can map keys to execute frequently used key sequences or to invoke an Ex command or to invoke a Vim function or to invoke external commands. Using key maps you can define your own Vim commands.
Use :map! and :map for manually set keys and :help 'char(-combination)' to find out which keys are already mapped in vim out-of-the-box(/out of your specific compiling options).
noremap is the "root" of all non-recursive mapping commands. The root form applies to the same modes as map . (Think of the nore prefix to mean "non-recursive".) (Note that there are also the ! modes like map! that apply to insert & command-line.)
Silent. Adding <silent> prevents stdout in Vim when a command runs. Sometimes when you execute a command call in Vim, it gets echoed.
It means the mapping is no n - re cursive.
To illustrate,
:nmap x dd
say you map x
in normal mode to dd
(delete line), to save up some time in well, deleting lines. Everything works fine, until you need the x (delete character) in some other mapping to delete two characters,
:nmap c xx
because now the upper mapping is really
:nmap c dddd
i.e. will delete two lines.
So, to preserve the "original" mappings (vim keys), you do it the non-recursive way,
:nnoremap x dd
:nnoremap c xx
and everything works (the mappings do not ... ah, you get the idea) ...
It is generally a good practice to do all your mapping with "nore", because you never know what plugins may be relying on what, and what vim behaviour you're breaking with "ordinary" mappings.
It's all covered in the built-in documentation
map
:
Map the key sequence {lhs} to {rhs} for the modes where the map command applies. The result, including {rhs}, is then further scanned for mappings. This allows for nested and recursive use of mappings.
And noremap
:
Map the key sequence {lhs} to {rhs} for the modes where the map command applies. Disallow mapping of {rhs}, to avoid nested and recursive mappings. Often used to redefine a command. {not in Vi}
nore
stands for non-recursive. It causes the right hand side of the mapping to ignore mappings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With