Search code examples
vimkey-bindingskeymapping

How to search through vim keymaps?


I often forget infrequently used keymappings, but i roughly remember the command name like make or PlugInstall. When i open :nmap i have to scroll through a long list of mappings to find the one i look for.

As suggested in https://stackoverflow.com/a/2240892/4936725 i currently export the keybindings into a file and grep through that.

:redir >> ~/mymaps.txt
:map
:redir END

Is there a more convenient way to search or grep through the keymaps list?


Solution

  • Vim 8 has introduced the :help :filter command that allows you to directly grep the output of a :map command:

    :filter /make/ nmap
    

    This is good for a quick-and-dirty lookup. You still get annoying false positives like <Plug> mappings, though. For a robust solution, you'd probably still capture the output with :redir, then split() it into lines and filter() (via multiple passes) for matching output.