Reputation: 1367
Is there any away to show a ordered list of all keyboard mappings of my current vim environment, like this:
a: append
b: back one word
c: ...
.
.
.
---- Ctrl mappings ----
<C-a> (I dont know...)
.
.
.
<C-p> Default mode for CrtlP
...
---- Alt mappings ----
...
This will be very useful for me.
Upvotes: 6
Views: 1543
Reputation: 426
You can also user the FZF Plugin which gives you the :Maps
command which brings up the same information as :verbose map
but in a pop up window that's fuzzy searchable. Its essentially the same as Tom Hales answer but an fzf version. I've mapped it to <leader>F1
.
Upvotes: 1
Reputation: 46973
If you want a sorted, searchable list of your current mappings in which to look 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 function to create a vertical split with the sorted output of :maps
. I put it in my vimrc
.
The last line maps the two keys \m to call the function, change this as you wish.
Note: As @romainl mentions, this will will not include commands like i to insert text
Upvotes: 2
Reputation: 196781
:map
and :verbose map
show you a list of the mappings defined in your session, but they are not ordered like that. AFAIK, Vim doesn't provide such a nice formatting: you'll have to write a custom function for that, I'm afraid.
edit
Also, note that a
, b
and friends are not "mappings" in the sense that CtrlP's <C-p>
is a mapping. :map
won't show them at all.
So your idea, while interesting, is probably not something that can be done with a one liner. You could pull info from :h index
, add the result of :map
and try to arrange all of that in an order that makes sense to you but it doesn't seem to be a trivial task. It sounds like a perfect fit for a python/ruby/php script, doesn't it?
endedit
Upvotes: 5