Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does nore mean when mapping keys in vim?

Tags:

vim

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
like image 261
xn. Avatar asked Apr 22 '12 21:04

xn.


People also ask

What is mapping in vim?

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.

How do you check if a key is mapped in Vim?

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).

What does Noremap mean in Vim?

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.)

What is the silent key in Vim?

Silent. Adding <silent> prevents stdout in Vim when a command runs. Sometimes when you execute a command call in Vim, it gets echoed.


3 Answers

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.

like image 95
Rook Avatar answered Oct 03 '22 22:10

Rook


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}

like image 30
Chris Morgan Avatar answered Oct 03 '22 22:10

Chris Morgan


nore stands for non-recursive. It causes the right hand side of the mapping to ignore mappings.

like image 25
xn. Avatar answered Oct 03 '22 23:10

xn.