Basically, I'd like to view all of the keys maps made in the current buffer by all of plugins, vimrc, etc, in the current buffer. Is there anyway to do this?
7 Answers
You can do that with the :map
command. There are also other variants.
:nmap
for normal mode mappings:vmap
for visual mode mappings:imap
for insert mode mappings
The above list is not complete. Typing :help map
in Vim will give you more info.
-
22Just for clarify, I believe
:map
, as the original question asks, just shows mappings made by plugins, vimrc, etc. If you want to see the default key bindings in vim, use:index
– VonMar 5, 2014 at 13:05 -
50
-
3these only give you the user-defined mappings, not the built-in (default) bindings Jul 15, 2014 at 14:49
-
1
-
2@AntonDaneyko You can use github.com/AndrewRadev/bufferize.vim for that purpose.– radlanApr 23, 2020 at 7:07
:redir! > vim_keys.txt
:silent verbose map
:redir END
This outputs the shortcuts, with where they were defined, to a text file.
-
1I believe that you meant to use the
:redir
command, not the:remap
command. Jan 16, 2014 at 13:40 -
1Thank you thank you thank you!!! Finally found that MacVim was remapping my <A-Up> command. Fixed by adding let macvim_skip_cmd_opt_movement = 1– RichSOct 23, 2015 at 8:39
-
1It is worth to note that
vim_keys.txt
file is located in working directory which can be checked by running:pwd
. Aug 14, 2020 at 11:15
In addition to answers about :map
with no arguments: do not miss its verbose form (:verbose map
) which shows where the mapping(s) was defined (see :help map-verbose
).
:map
and its friends are the key, :verbose
adds info and :redir
allow post-search refinement.
They are a perfect mix to show what command is bind to what shortcut and viceversa, but if you want to search some keys and avoid temp files whenever you need to search mappings, take a look to scriptease and :Verbose
command.
It is a wrapper on :verbose
to show result in a preview window.
this way you can search whatever you want inside results without using temp files
type :Verbose map
and use / ? as usual.
Another way is to save session to a file and then edit this file as it contains all the mappings and settings.
:mks[ession] [file]
- Write a Vim script that restores the current editing
session.
install this plug like this:
Plug 'https://github.com/tpope/vim-scriptease'
what will <M-C-F10>
(my own mapping) do?
try this
:Verbose nmap <M-C-F10> | omap <M-C-F10> | vmap <M-C-F10> | imap <M-C-F10> | cmap <M-C-F10> | tmap <M-C-F10>
put it in a function:
func! Leo_keymap(keys)
exe "verbose map " . a:keys
exe "verbose map! " . a:keys
exe "verbose tmap " . a:keys
" 不好:
" exe "verbose nmap " . a:keys
" exe "verbose omap " . a:keys
" exe "verbose vmap " . a:keys
" exe "verbose imap " . a:keys
" exe "verbose cmap " . a:keys
" exe "verbose tmap " . a:keys
" 不行
" exe "Verbose map " . a:keys . <Bar> . "verbose map! " . a:keys . <Bar> . "verbose tmap " . a:keys
endfunc
cnoreabbrev <expr> map getcmdtype() == ":" && getcmdline() == 'map' ? 'Verbose call Leo_keymap("")<left><left>' : 'map'
" 不行
" command! -nargs=* Map :new<CR>:put = Vim_out('call Leo_keymap(input())')
" 不行
" :put = Vim_out("call Leo_keymap('ls')")
" may be take placed by the above line
cnoreabbrev <expr> nmap getcmdtype() == ":" && getcmdline() == 'nmap' ? 'Verbose map' : 'map'
cnoreabbrev <expr> imap getcmdtype() == ":" && getcmdline() == 'imap' ? 'Verbose imap' : 'imap'
cnoreabbrev <expr> cmap getcmdtype() == ":" && getcmdline() == 'cmap' ? 'Verbose cmap' : 'cmap'
cnoreabbrev <expr> tmap getcmdtype() == ":" && getcmdline() == 'tmap' ? 'Verbose tmap' : 'tmap'
old content, may be useless:
func! Leo_keymap(keys)
exe "verbose map " . a:keys
exe "verbose map! " . a:keys
exe "verbose tmap " . a:keys
" exe "Verbose map " . a:keys . <Bar> . "verbose map! " . a:keys . <Bar> . "verbose tmap " . a:keys
" exe "verbose nmap " . a:keys
" exe "verbose omap " . a:keys
" exe "verbose vmap " . a:keys
" exe "verbose imap " . a:keys
" exe "verbose cmap " . a:keys
" exe "verbose tmap " . a:keys
endfunc
command! -nargs=* Map :call Leo_keymap(<q-args>)
now :Map d
gets:
n dL * v$hhd
Last set from ~/dotF/cfg/nvim/plug_wf.vim line 712
n df * ggdG
Last set from ~/dotF/cfg/nvim/clipboard_regis.vim line 250
n dB * %dab
Last set from ~/dotF/cfg/nvim/clipboard_regis.vim line 230
n d" * da"
Last set from ~/dotF/cfg/nvim/clipboard_regis.vim line 212
n dw * diw
Last set from ~/dotF/cfg/nvim/clipboard_regis.vim line 211
n d' * :call DoubleAsSingle()<CR>da'
Last set from ~/dotF/cfg/nvim/clipboard_regis.vim line 195
No mapping found
No mapping found
Press ENTER or type command to continue
So far, I don't know how to combine this with :Verbose .....
:help index
to see the VIM's default key bindings. (Credit to Von and Lqueryvg)