检测某个键是否绑定到 vim 中的某个东西

发布于 2024-08-26 10:12:32 字数 258 浏览 3 评论 0原文

我想知道是否有办法确定 vim 中某个键是否执行某些操作。我知道我可以使用 :map 来查看用户定义的映射,但是有内置的东西吗?

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

雪落纷纷 2024-09-02 10:12:33

如果您查看兰迪·莫里斯的建议答案,您会发现它

:help index 

会给您所需的列表。

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

:help index 

will give you the list you want.

以歌曲疗慰 2024-09-02 10:12:33

要检查默认映射:

:help index

对于由用户或插件完成的其他映射:

:map
:map!

来自 http://vim .wikia.com/wiki/Mapping_keys_in_Vim_-教程(Part_1)

第一个命令显示在正常、视觉和
选择和操作员挂起模式。第二个命令显示地图
在插入和命令行模式下工作。

上述命令的输出通常会跨越几页。
您可以使用以下一组命令将输出重定向到
vim_maps.txt 文件:

<前><代码>:重定向! > vim_maps.txt
:地图
:地图!
: 重定向结束

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
雨落星ぅ辰 2024-09-02 10:12:33

这不是一个完整的答案,但您可能需要查看 :help map-which-keys 以获得 vim 建议您在自定义地图中使用的键列表。

该帮助部分提供了如何判断特定键是否映射到操作的建议。

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.

黯淡〆 2024-09-02 10:12:33

我浏览了 :help index 并列出了一些未使用的 nmap 键:

  • Q(切换到“Ex”模式)
  • Z 除 ZZ、ZQ
  • \
  • (与普通模式下的 l 相同;普通模式下最大且最未被充分利用的键)
  • 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(保留用于扩展)
  • CTRL-\ A - Z(未使用)

请更新/评论。

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.

清眉祭 2024-09-02 10:12:33

使用 :map!:map 手动设置键,使用 :help 'char(-combination)' 找出哪些键已经映射在 vim 中开箱即用(/超出您的特定编译选项)。
(有点偏离主题,但仍然值得关注(我认为):使用 :scriptnames 来查看哪些文件是按什么顺序获取的。)

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

厌倦 2024-09-02 10:12:33

您可以使用 mapcheck.:-

例如,我想映射 ; ,igg=G 来缩进文件。
要检查 是否已存在映射: , i

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

...但这不会检测映射是否是序列的一部分。

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.

遇见了你 2024-09-02 10:12:33

仅为了完成这篇非常古老的文章,以下内容将打印是否设置了特定的键绑定以及由什么源设置。如果映射发生冲突/重叠,verbose 关键字将为您提供设置绑定的源的列表。例如,对于 ... 在正常模式下:

:verbose nmap <C-n>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文