301

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?

4
  • 8
    Try :help index to see the VIM's default key bindings. (Credit to Von and Lqueryvg) Commented Jul 28, 2020 at 6:46
  • 8
    If you're using Telescope (neovim) then you can use :Telescope keymaps to view/fuzzy search them. Or if you use whichkey you can navigate keymaps through a menu. Commented Dec 16, 2022 at 16:40
  • 2
    @artfulrobot It seems like you accidentally linked to Telescope twice instead of linking to whichkey. Is this the right link: github.com/folke/which-key.nvim. 🤔 5 months since you posted that and I'm the first to mention it. Commented May 8, 2023 at 5:19
  • Without a doubt @artfulrobot has the MVP comment here. Commented Jul 10, 2023 at 1:26

7 Answers 7

393

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Just 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
@Von, you perhaps mean :help index.
these only give you the user-defined mappings, not the built-in (default) bindings
@AntonDaneyko You can use github.com/AndrewRadev/bufferize.vim for that purpose.
The result is huge, could I grep or search (/) on their output?
|
145
:redir! > vim_keys.txt :silent verbose map :redir END 

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

4 Comments

I believe that you meant to use the :redir command, not the :remap command.
It is worth to note that vim_keys.txt file is located in working directory which can be checked by running :pwd.
This is great but doesn't capture insert and command mode mappings, to see everything use :redir! >> vim_keys.txt :silent verbose map :silent verbost map! :redir END
@BrittonKerin: That sounds useful, but I'm having a hard time reading those steps because of the lack of delimiters. Can you put inverted commas (`), AKA 'back ticks', around the commands, please, so they look like this, or ideally, submit a separate answer, so you'll get some credit as well? Cheers.
69

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

1 Comment

Thus is exactly the tip I did not know I needed, thanks!
19

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

:map :imap :vmap 

Comments

17

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

Comments

9

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.

Comments

2
  1. Install this plug like this: Plug 'https://github.com/tpope/vim-scriptease'

  2. What to know what <M-C-F10>(my own mapping) does? 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 " 不好 / not good: " 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 " 不行 / not work " 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' " 不行 / not work " command! -nargs=* Map :new<CR>:put = Vim_out('call Leo_keymap(input())') " 不行 / not work " :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 .....

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.