111

I'd like to know if there is a way to figure out if a key does something in vim. I know that I can use :map to see user-defined mappings, but is there something for the built-in stuff?

For example, I always had CTRL-W bound to close tab, because I thought that it was unused. After half a year, I found out that there are some sequences that use it, like CTRL-W CTRL-S to split the window, and it was a nightmare to retrain myself.

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
K. Norbert
  • 10,494
  • 5
  • 49
  • 48
  • 5
    Speaking of accidental collisions of user-defined mappings, it's really a good practice to use [_mapleader_](http://vimdoc.sourceforge.net/htmldoc/map.html#mapleader) – derenio Feb 27 '13 at 13:43

7 Answers7

97

If you check out the suggested answer by Randy Morris you will find that

:help index 

will give you the list you want.

skeept
  • 12,077
  • 7
  • 41
  • 52
  • very useful! good to know there's a place you can go look if you just want to poke around to learn something new – JonnyRaa Apr 13 '15 at 13:01
52

To check the default mapping:

:help index

For other mapping that is done by either users or plugin:

:map
:map!

From http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_1):

The first command displays the maps that work in normal, visual and select and operator pending mode. The second command displays the maps that work in insert and command-line mode.

Typically the output of the above commands will span several pages. You can use the following set of commands to redirect the output to the vim_maps.txt file:

:redir! > vim_maps.txt
:map
:map!
:redir END
Hieu
  • 7,138
  • 2
  • 42
  • 34
  • Unless newer versions of Vim suddenly offers a better alternative, this seems to be the only way to search both included and custom keymaps. `mapcheck` (as mentioned in [another answer](https://stackoverflow.com/a/19726877/6296561)) also only covers custom keybinds. The main difference between outputting to a text file and mapcheck is that outputting to a text file and/or using `:help index` lets you `/C-w` in Vim to find anything using `C-w` – Zoe Aug 14 '19 at 15:01
37

Not a complete answer, but you may want to check out :help map-which-keys for a list of keys that vim recommends you to use in your custom maps.

That help section has a recommendation of how to tell if a specific key is mapped to an action.

Randy Morris
  • 39,631
  • 8
  • 69
  • 76
23

I skimmed through :help index and made a list of some of the unused nmap keys:

  • Q (switch to "Ex" mode)
  • Z except ZZ, ZQ
  • \
  • <Space> (same as l in the normal mode; the largest and the most underutilized key in the normal mode)
  • gb, gc, gl, gx, gy, gz
  • gs (sleep)
  • zp, zq, zu, zy
  • cd, cm, co, cp, cq, cr, cs, cu, cx, cy
  • dc, dm, do, dp, dq, dr, ds, du, dx, dy
  • gA, gB, gC, gG, gK, gL, gM, gO, gS, gX, gY, gZ
  • zB, zI, zJ, zK, zP, zQ, zP, zS, zT, zU, zV, zY, zZ
  • ]a, ]b, ]e, ]g, ]h, ]j, ]k, ]l, ]n, ]o, ]q, ]r, ]t, ]u, ]v, ]w, ]x, ]y
  • [a, [b, [e, [g, [h, [j, [k, [l, [n, [o, [q, [r, [t, [u, [v, [w, [x, [y
  • CTRL-G, CTRL-K
  • CTRL-\ a - z (reserved for extensions)
  • CTRL-\ A - Z (not used)

Please update/comment.

Michal Čizmazia
  • 875
  • 1
  • 8
  • 14
19

Use :map! and :map for manually set keys and :help 'char(-combination)' to find out which keys are already mapped in vim out-of-the-box(/out of your specific compiling options). (Slightly off-topic but still regardable (I think): Use :scriptnames to see which files have been sourced in which order.)

Zoe
  • 27,060
  • 21
  • 118
  • 148
shindojin
  • 191
  • 1
  • 2
  • If you want to search for what keys trigger a certain command, you can do this: :redir keys.txt :map :redir end Then open keys.txt and search for what commands are bound. – Christian Oudard Sep 14 '12 at 16:55
15

You can use mapcheck.:-

For example, I wanted to map <CR> ,i to gg=G to indented a file. To check if there is a mapping already for <CR> , i

if mapcheck("\<CR>", "I") == "" |echo "no mapping"

...but this won't detect if the mapping is part of a sequence.

benomatis
  • 5,536
  • 7
  • 36
  • 59
Moha the almighty camel
  • 4,327
  • 4
  • 30
  • 53
  • I tried to check if "o" is bound to something in normal mode, with the following: if mapcheck("o", "N") == "" | echo "no mapping" but it reports "no mapping", when o is definitely bound to "open new line". Am I using it wrong? – K. Norbert Jan 03 '14 at 10:48
  • @K.Norbert: I believe this for user defined mappings – Moha the almighty camel Apr 23 '14 at 12:06
2

Only to complete this very old post, the following will print if and by what source a specific keybinding was set. In the event the mappings collided/overlapped, the verbose keyword will provide you the list of which sources set the binding. e.g., for <C-n>... in normal mode:

:verbose nmap <C-n>
Edmund's Echo
  • 766
  • 8
  • 15