如何在 vim using map 中使用 ctrl + / 作为快捷方式? (<C-_> 无效)

How do I use ctrl + / as a shortcut in vim using map? (<C-_> doesn't work)

我正在为 vim 使用名为 NERDCommenter 的插件,它允许我切换代码行的注释状态。问题是我想将快捷方式更改为 ctrl + / 或 command + /。网上(从我读到的其他帖子)说不要使用 <C-/>,而是使用 <C-_>。这不起作用,只能将切换注释命令映射到 ctrl 下划线。

这是我用来执行此操作的代码:

nnoremap <C-_> :call NERDComment(0, "toggle")<CR>

有人可以让我知道我做错了什么吗?谢谢。

在撰写本文时,在 MacOS 中使用 current/built-in Terminal 应用程序(未使用其他软件),不幸的是 不可能 使用 Control+/ 或 [=55 映射 Vim 快捷方式=]命令 ⌘+/.

这是因为这两个键序列都没有控制代码编码(更多内容 here and here)。


选项 #1(推荐)

映射Option/Alt+/切换NERDCommenter → mac用户必须使用真实角色(÷ ) 由 Option/Alt 序列生成以执行此操作:

nmap ÷ <plug>NERDCommenterToggle
vmap ÷ <plug>NERDCommenterToggle<CR>gv

仅在终端>首选项>配置文件[设置]>键盘>'Use Option as Meta Key'切换为OFF[=69时有效=]。更多信息 here.

选项 #2 - MacVim

您可以使用 MacVim which allows you to map the Command ⌘ key with <D->. More info .

选项 #3 - iTerm2

为您的终端应用程序使用 iTerm2。这样你就可以将 Control+/ 映射到 <C-_> 并且它会起作用。要使 Command ⌘+/ 起作用,您必须创建一个新的键盘快捷键以作为转义序列发送到 Vim .更多信息 and here.


我不建议这样做,但您也可以每次都使用程序重新映射您的 Command ⌘Control 修改键您打开一个特定的应用程序,例如 TerminaliTerm2 也适用于此任务,像 Karabiner -- for older versions of MacOS. According to this post, the newer Karabiner-Elements 这样的程序需要对 app-specific 重新映射进行一些调整。

更多资源here, here, and here.