“M-” iTerm2/Terminal 上的 vim 绑定不起作用

发布于 2024-12-17 03:55:08 字数 664 浏览 6 评论 0 原文

我注意到 iTerm2 提供了非常方便的功能,可以使用“Option key as +ESC”(或作为元,但是显然这已经过时了)。

我尝试了它们,选项键在 Bash(set -o emacs 模式)和 Emacs 中按预期工作,但在 Vim 中却不行。因此,我无法使用任何“M-”绑定。 我发现:

  • 如果我将选项设置为“+ESC”,vim 只会理解 ESC+key,并且不知道我实际上指的是 Meta-key。
  • 如果我将 option 设置为“meta”,则用“option”修改的键的行为就像没有修饰符一样(不知道如何正式测试 vim 从我键入的组合键中理解的内容)。

“M-”映射在 MacVim (7.3.53) 中完美工作,但那不在控制台之外,不在这个问题的范围内。

我感兴趣的是如何使这些映射在 Vim 中的 iTerm2 或 Terminal 下工作。

我的规格

  • MAC OS X Lion 10.7.2
  • iTerm2 1.0.0.20111020
  • vim @7.3.107_0+python26 [尽管MacPorts]

I noticed that iTerm2 offers the very convenient feature of using "Option key as +ESC" (or as meta, but apparently that's obsolete).

I tried them both and the option key works as expected in Bash (set -o emacs mode) and Emacs, but not in Vim. Thus, I can't make use of any "M-" bindings.
What I've found is that:

  • if I set option to "+ESC", vim just understands ESC+key, and has no idea I actually meant Meta-key.
  • if I set option to "meta", keys modified with "option" behave just as without a modifier (don't know how to formally test what vim understands from a key combination that I'm typing).

"M-" mappings work perfectly in MacVim (7.3.53), but that's outside of a console and not in the scope of this question.

I'm interested in how to make those mappings work in Vim, under iTerm2 or Terminal.

My specs:

  • MAC OS X Lion 10.7.2
  • iTerm2 1.0.0.20111020
  • vim @7.3.107_0+python26 [though MacPorts]

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

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

发布评论

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

评论(3

念三年u 2024-12-24 03:55:08

我已经下载了最新的 iTerm2 并尝试查看它发送到的内容/Vim 打印的内容 (i),设置如下:

  • Option作为选项:

    Vim 打印 æ 这是正常的,在我的法语键盘上是正常的

  • 选项作为元:

    Vim 呆在那里,等待事情发生。没有打印任何内容。如果我依次按 Option 和 a,我只会获得 a。以某种随机顺序按 Option 和 a 可能会打印 á,这很奇怪并且完全出乎意料。

  • 选项为+ESC:

    Vim 打印 ^[a 这意味着“转义字符后跟字符 a”。

从这些测试来看,如果没有一些假设的黑魔法,Vim 永远不会收到

如果您坚持使用“Option as +ESC”,则似乎您必须将所有自定义 映射更改为 ;某事。这可能有效,但它会让用任何非英语语言写任何类型的散文变得痛苦。

我所做的:我保留 Option 键不变,这样我就可以轻松键入 œ…«» 之类的字符,并使用 (映射到 ,,请参阅 :help mapleader) 了解我的所有自定义映射。

这里的一些人喜欢将其保留给插件,并提倡一种更简单且可能更安全的方法。

inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
inoremap ,, <C-x><C-o>        "another way

I've downloaded the latest iTerm2 and tried to see what it sent to/what was printed by Vim (i<C-v><M-a>) with the following settings:

  • Option as Option:

    Vim prints æ which is normal and expected on my french keyboard

  • Option as Meta:

    Vim stays there, waiting for something to happen. Nothing is printed. If I press Option and a in sequence I just obtain a. Pressing Option and a in some random order may print á, which is weird and totally unexpected.

  • Option as +ESC:

    Vim prints ^[a which means "Escape character followed by the character a".

From these tests it appears that Vim will never ever receive <M-> without some hypothetical black magic.

If you stick with "Option as +ESC", it seems that you will have to change all your custom <M-something> mappings to <Esc>something. This may work but it will make writing any kind of prose in any non-english language a pain.

What I do: I leave the Option key as it is so that I can type characters like œ…«» easily and I use <Leader> (mapped to ,, see :help mapleader) for all my custom mappings.

Some people here like to reserve it for plugins and advocate a somewhat simpler and potentially safer approach.

inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
inoremap ,, <C-x><C-o>        "another way
那伤。 2024-12-24 03:55:08

我将选项键设置为普通,发现 Vim 将它们视为 绑定。因此,例如,我在 .vimrc 中有此映射设置,以便在插入模式下移动到单词的末尾:

noremap! <T-Right> <C-o><Right>;

I left my option key to act as Normal and discovered that Vim saw them as <T- bindings. So, for example, I have this mapping setup in my .vimrc to move to the end of a word when in Insert mode:

noremap! <T-Right> <C-o><Right>;
绝對不後悔。 2024-12-24 03:55:08

以下是我在 iterm2 (版本:3.4.23)中的关键设置:

  1. 左/右选项键 -> Esc+
  2. 检查xterm控制序列可以启用modifyOtherKeys模式

< img src="https://i.sstatic.net/6lVu6.png" alt="在此处输入图像描述">

Here were the key settings in iterm2 (version: 3.4.23) for me:

  1. Left/Right Option key -> Esc+
  2. Check xterm control sequence can enable modifyOtherKeys mode

enter image description here

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