Listing Neovim Key Mappings


Occasionally we all forget which key mapping we defined for which action, and need to go review the mapping to recall. Similarly, sometimes we want to modify a key mapping but don't recall exactly where it was defined. Neovim has a pretty convenient built-in mechanism to help with these scenarios.

The most basic form of listing key mapping is the :map command, which lists all key mappings defined for all modes:

:map

While comprehensive, the amount of content can be a bit unwieldy. For this reason, Neovim includes several ways to filter the output. The :map command is one of a group of commands that can be used to list key mappings. In fact, while this command lists all key mapping, regardless of mode, the others limit their output to their specific mode. They are:

Command Description
:map Display key bindings for all modes
:nmap Display key bindings for normal mode
:vmap Display key bindings for visual mode
:imap Display key bindings for insert mode

The next filter that we will look at is allows us to filter the list according to the {lhs}. For example, to see key mappings with {lhs} starting with g:

:map g

Of course, these filters can be combined. Repeating for normal mode key mappings:

:nmap g

The next filter limits the output to buffer-local key mappings:

:map <buffer>

The :filter command provide some additional flexibility when filtering mappings.

:filter {pattern} {command}

When used, :filter matches the specified pattern against {lhs}, {rhs} and {desc} fields, which makes it handy to list key mappings when you only remember a portion of the description, for example. This is one reason to apply sensible desc entries when creating key mappings.

When verbose is used the listing will also display where the key mapping was defined. This is useful for locating where to go to modify the key mapping.

Finally, while most of this section focuses on limiting the amount of output, the final topic uses the :verbose command to increase the amount of output we get for each entry This command can be involved with the following signature:

:verbose {command} {pattern}

For example, to see normal-mode key mappings starting with g:

:verbose nmap g

When the :verbose command is used the output includes an additional line that indicates from where the key mapping most-recently set, which can be helpful when locating a key mapping definition.