DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

How to Debug Key Mappings in Vim

Sometimes my mapping not working since overridden by plug-in or I forget a mapping and want to select from all my mappings list.

All List

If you want to get all your key mappings run:

:map <key>
Enter fullscreen mode Exit fullscreen mode

Specific Key

If you only want to know specific key(s) run:

:map <key>
Enter fullscreen mode Exit fullscreen mode

Like examples below:

:map <leader>f
:map H
:map <F8>
Enter fullscreen mode Exit fullscreen mode

Verbose Mode - Show Overridden

If you can't use your mapping and want to know what overrides it just run with
verbose:

:verbose map <key>
Enter fullscreen mode Exit fullscreen mode

This will show all configs that uses given mapping in a list and last
set
location:

vim mapping

Also it is possible to use :map with visual, normal, insert etc. as
well:

:vmap rn
:nmap rn
:imap rn
Enter fullscreen mode Exit fullscreen mode

All done!

Top comments (1)

Collapse
 
brandonwallace profile image
brandon_wallace

Nice article Serhat.

The *map command are recursive which can cause issues with plugins that map to the same keys.

Here is an example:

nmap x j        # Your mapping
nnoremap j x    # Plugin mapping
Enter fullscreen mode Exit fullscreen mode

You want x to move the cursor down a line but the plugin maps j to delete one character.
Now when you press x to move down one line you end up deleting a character.

nnoremap x j    # Your mapping
nnoremap j x    # Plugin mapping
Enter fullscreen mode Exit fullscreen mode

Now both mappings work.

It is much better to use nnoremap, inoremap, vnoremap to map your keys.