xn.
xn.

Reputation: 16016

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

Upvotes: 8

Views: 1785

Answers (5)

Good Pen
Good Pen

Reputation: 801

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.

Upvotes: 1

Chris Morgan
Chris Morgan

Reputation: 90752

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}

Upvotes: 3

Rook
Rook

Reputation: 62538

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.

Upvotes: 19

xn.
xn.

Reputation: 16016

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

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324640

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

Upvotes: 0

Related Questions