nnoremap nmap confusion

43 views
Skip to first unread message

Kai Weber

unread,
Aug 14, 2019, 10:26:39 AM8/14/19
to vim...@googlegroups.com
The plugin srstevenson/vim-picker defines a list of mappings:

nnoremap <silent> <Plug>(PickerEdit) :PickerEdit<CR>

I tried to bind this mapping with

nnoremap <unique> <leader>E <Plug>(PickerEdit)

This fails with no error but the function seems to be not called. I get
a "beep" from my terminal bell. map shows me

n ,E * <Plug>(PickerEdit)

If I use nmap to bind the mapping this works:

nmap <unique> <leader>E <Plug>(PickerEdit)

and map shows:

n ,E <Plug>(PickerEdit)

The star (*) is missing in the nmap defined mapping. What does this star
mean? I always use nnoremap because of cargo-cult. This seems to be
wrong?

Kai

Andy Wokula

unread,
Aug 14, 2019, 11:37:45 AM8/14/19
to vim...@googlegroups.com
Am 14.08.2019 um 16:26 schrieb Kai Weber:
> The plugin srstevenson/vim-picker defines a list of mappings:

I read those https://github.com/srstevenson/vim-picker README for you:
it suggests :nmap for your mappings ... no cargo-cult here.

--
Andy

Kai Weber

unread,
Aug 14, 2019, 3:51:11 PM8/14/19
to 'Andy Wokula' via vim_use
* 'Andy Wokula' via vim_use <vim...@googlegroups.com>:

> > The plugin srstevenson/vim-picker defines a list of mappings:
>
> I read those https://github.com/srstevenson/vim-picker README for you:
> it suggests :nmap for your mappings ... no cargo-cult here.

You are right. But why?
Why does nnoremap not work?

Kai

Rob Foehl

unread,
Aug 14, 2019, 3:59:20 PM8/14/19
to vim...@googlegroups.com
On Wed, 14 Aug 2019, Kai Weber wrote:

> Why does nnoremap not work?

Because <Plug> mappings are just that, and the entire point of the noremap
versions is to not execute other mappings.

-Rob

Andy Wokula

unread,
Aug 15, 2019, 3:50:08 PM8/15/19
to vim...@googlegroups.com
:nmap
= remapping on
=check the right hand side for user-defined left-hand-sides (and expand them recursively)
when it comes to executing the mapping

:nnoremap
= remapping off
= interpret the right hand side as if there were no mappings defined

There is no builtin command starting with <Plug>
(and important for plugin writers: there is no key "<Plug>" on your keyboard).
(If you need a beep, try
:exec "normal! \<Plug>"
)
The only thing starting with <Plug> is a user-defined mapping, usually from a plugin.


Help pointers:
:h :nmap
:h :nnoremap
:h <Plug>
:h map-listing
the latter explains `*' in the map listing.

(:help is essential. Also try <Tab> and Ctrl-D for completion, and wildcards `*' and `?'
search around with `/', try :helpgrep, etc.).


" ok:
:nnoremap <silent> <Plug>(PickerEdit) :PickerEdit<CR>

" wrong:
:nmap <silent> <Plug>(PickerEdit) :PickerEdit<CR>
" eg user swapped `;' and `:' via mapping => right hand side becomes `;PickerEdit<CR>'

" ok:
nmap <unique> <Leader>E <Plug>(PickerEdit)

" wrong:
nnoremap <unique> <Leader>E <Plug>(PickerEdit)
" just beeps, no builtin command starting with <Plug>

--
Andy

Kai Weber

unread,
Aug 16, 2019, 8:09:53 AM8/16/19
to 'Andy Wokula' via vim_use
* 'Andy Wokula' via vim_use <vim...@googlegroups.com>:

> " wrong:
> nnoremap <unique> <Leader>E <Plug>(PickerEdit)
> " just beeps, no builtin command starting with <Plug>

Wow! Thank you very much for the detailed explanation. I understand now.

Kai
Reply all
Reply to author
Forward
0 new messages