简体   繁体   中英

What does nore mean when mapping keys in 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

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

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

It helps if you read the whole word. "noremap", as in "no re-map". Meaning that the mapping can't be changed.

I think it was vi that made such a counter intuitive setting, which makes map stand for recursive map, instead of explictly adding re to inply recursive map

https://learnvimscriptthehardway.stevelosh.com/chapters/05.html

When should you use these nonrecursive variants instead of their normal counterparts?

Always.

No, seriously, always.

Using a bare *map is just asking for pain down the road when you install a plugin or add a new custom mapping.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM