Reputation: 582
In vim:
:map
list all key mappings:map {lhs}
list all key mappings for the key sequences starting with {lhs}.How do you seach for "all key mappings starting with the control key" ?
(I know I can still list all mappings, redirect the output to a file and grep; but it is not very efficient).
Thanks !
Upvotes: 2
Views: 1119
Reputation: 46745
If you want a sorted, searchable list of :maps
output in which to search for <C-
, 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: This will will not include vim's default commands like Ctrl-a to increment a number, as they are not made with map
. See :help index
for these.
Upvotes: 1
Reputation: 196476
No, there's no direct, built-in, method for that.
What you can do instead is:
:redir @a redirect output of next command to register a
:map list mappings
:redir END end redirection
:vnew edit new buffer in vertical window
:put a put content of register a
:v/<C-/d delete all lines not matching '<C-'
Which you could turn easily into a function.
Upvotes: 9