检测密钥是否绑定到 vim 中的某个内容

我想知道有没有办法知道一把钥匙是否能在 Vim 中起作用。我知道我可以使用 :map来查看用户定义的映射,但是对于内置的东西有什么东西吗?

例如,我总是将 CTRL-W绑定到关闭选项卡,因为我认为它是未使用的。半年后,我发现有一些序列使用它,如 CTRL-W CTRL-S分裂窗口,这是一个噩梦重新训练自己。

48492 次浏览

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.

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

:help index

will give you the list you want.

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

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

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.

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(睡眠)
  • 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.