Display Ordered VIM Keyboard Mapping

Is it possible to display an ordered list of all keyboard mappings of my current vim environment, for example:

a: append b: back one word c: ... . . . ---- Ctrl mappings ---- <Ca> (I dont know...) . . . <Cp> Default mode for CrtlP ... ---- Alt mappings ---- ... 

It will be very useful for me.

+6
source share
2 answers

:map and :verbose map will show you a list of mappings defined in your session, but they are not ordered like this. AFAIK, Vim does not provide such a pleasant formatting: you will have to write a special function for this, I'm afraid.

change

Also note that a , b and friends are not β€œmappings” in the sense that CtrlP <Cp> is a mapping. :map will not show them at all.

So, your idea, although interesting, probably cannot be carried out with a single liner. You can output information from :h index , add the result :map and try to organize all this in an order that makes sense to you, but this does not seem to be a trivial task. That sounds perfect for a python / ruby ​​/ php script, right?

Endedit

+5
source

If you need a sorted, searchable list of your current mappings to search for unused keys, you can do the following:

 function! s:ShowMaps() let old_reg = getreg("a") " save the current content of register a let old_reg_type = getregtype("a") " save the type of the register as well try redir @a " redirect output to register a " Get the list of all key mappings silently, satisfy "Press ENTER to continue" silent map | call feedkeys("\<CR>") redir END " end output redirection vnew " new buffer in vertical window put a " put content of register " Sort on 4th character column which is the key(s) %!sort -k1.4,1.4 finally " Execute even if exception is raised call setreg("a", old_reg, old_reg_type) " restore register a endtry endfunction com! ShowMaps call s:ShowMaps() " Enable :ShowMaps to call the function nnoremap \m :ShowMaps<CR> " Map keys to call the function 

This is a robust feature for creating vertical separation with sorted output :maps . I put it in vimrc .

The last line displays the two \ m keys for calling the function, change it as you like.

Note. As @romainl mentions, this will not include type i commands to insert text

+2
source

All Articles