7

From time to time I want to search on the list of my currents mappings. I search either for mapped keys (what /<Space>a does?) or for a command (What keys are mapped on /MyFunction()<CR>?)

I know that I can output these mappings with :map (or :nmap, :vmap, etc...) but this open a window where I can only scroll and not use search mode /.

So when I want to search in this list I have to use redir to put the result of the command in a new file, which I then open in vim and use search mode:

:redir > foo
:map
:redir END
:e foo

I feel like this workflow is not natural:

  • It uses a lots of commands compared to what I want to do.
  • It creates a new file that I have to delete.

So my question is is there a more natural way to do a search in the currently mapped keys?

I know that I could create a function which would executes these commands and a custom command to easily call the function, but I was wondering if there wouldn't be a more straight forward way to do it.

3

A very easy way to search for a mapping uses a plugin. But the good news is, you probably have it already.

The command is:

:Unite mapping -start-insert

... then you basically directly type your search term and narrow down the list.


Without a plugin, you can still narrow your map results by providing the prefix of the map, and its type. For example:

:verbose xmap <leader>

... will show the defined mappings only for visual mode, and which start with the leader key. You are not limited to one character there (e.g. you can use xmap <leader>a and so on).

  • I heard of this plugin before but never tried it I'll give it a try thanks! Also the second suggestion is nice but doesn't allow to do the second type of search i.e. which keys are mapped to execute this function. – statox Sep 2 '15 at 22:27
  • Indeed - you can do that with the 1st suggestion. And 'Unite' (and its extensions) = the Swiss knife of Vim plugins :) – VanLaser Sep 2 '15 at 22:47
  • 1
    Ok I'll look at it closely then thank you very much! – statox Sep 2 '15 at 22:50
2

:map, :imap and friends take an argument so, instead of issuing a generic command and then filtering it you could simply issue a specific command from the get go:

:imap <CR>
  • That's a great way to do it thanks but as for VanLaser answer I stil have a question: this doesn't allow me to make a search on MyFunction to know which keys are mapped to call it. – statox Sep 2 '15 at 22:29

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.