2

The vim-easy-align plugin says to assign the following keymaps:

xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)

I thought these would work equally well with:

xnoremap ga <Plug>(EasyAlign)
nnoremap ga <Plug>(EasyAlign)

but it doesn't. I thought map is recursive and noremap is non-recursive, and since there is no recursion, they should behave identically here. Why not?

5

Let's start with the difference between recursive mapping and non-recursive mapping.

In a recursive mapping (nmap, xmap, etc.), the keys you use in the right hand side of your mapping are used "as is". If they are already mapped at the time of execution those mappings are respected:

" here we remap b to work like B
nmap b B

" <F5> thus works like dB instead of db because it uses the new meaning of b
nmap <F5> db

In a non-recursive mapping (nnoremap, xnoremap, etc.), the keys in the right hand side are used in their original meaning. If they are already mapped at the time of execution those mappings are not respected:

" here we remap b to work like B
nmap b B

" <F5> works like db because it uses the original meaning of b
nnoremap <F5> db

<Plug>(EasyAlign) being a mapping, it is respected by recursive mappings and ignored by non-recursive ones.

The rules are:

  • Use a recursive mapping if you want to use another mapping in your mapping.
  • Use a non-recursive mapping if you don't.
  • 3
    What may be confusing (it was, for me) is that defining a <Plug> (i.e. mapping it to do something, as opposed to mapping some key combo to a <Plug>) will normally use the non-recursive forms, as recommended when you need to know exactly what action to expect. That's usually a task for plugin authors, but one can stumble upon such examples (e.g. in usr_41.txt) – VanLaser Sep 15 '16 at 14:38
  • Now to fix my 2778 line .vimrc xD – FocusedWolf Aug 9 '17 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.