Is there any way to view the currently mapped keys in Vim?

Vim

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

:redir! > vim_keys.txt
:silent verbose map
:redir END

This outputs the shortcuts, with where they were defined, to a text file.

Solution 3 - Vim

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).

Solution 4 - Vim

Quite simply, just run the :map variants with no arguments.

:map
:imap
:vmap

Solution 5 - Vim

: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.

Solution 6 - Vim

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.

Solution 7 - Vim

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 .....

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul WicksView Question on Stackoverflow
Solution 1 - Vimmattr-View Answer on Stackoverflow
Solution 2 - VimIvanView Answer on Stackoverflow
Solution 3 - VimVesView Answer on Stackoverflow
Solution 4 - VimMichael BerkowskiView Answer on Stackoverflow
Solution 5 - VimalbfanView Answer on Stackoverflow
Solution 6 - VimFernando RodriguezView Answer on Stackoverflow
Solution 7 - VimGood PenView Answer on Stackoverflow