“M-"iTerm2/Terminal 上的 vim 绑定不起作用 [英] "M-" bindings in vim on iTerm2/Terminal don't work
问题描述
我注意到 iTerm2 提供了使用Option key as +ESC"(或作为元,但显然这已经过时了).
I noticed that iTerm2 offers the very convenient feature of using "Option key as +ESC" (or as meta, but apparently that's obsolete).
我尝试了它们,选项键在 Bash(set -o emacs
模式)和 Emacs 中按预期工作,但在 Vim 中没有.因此,我不能使用任何M-"绑定.我发现的是:
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:
- 如果我将选项设置为+ESC",vim 只会理解 ESC+key,并且不知道我实际上是指 Meta-key.
- 如果我将选项设置为meta",用option"修改的键就像没有修饰符一样(不知道如何正式测试 vim 从我输入的组合键中理解的内容).
"M-" 映射在 MacVim (7.3.53) 中完美运行,但这不在控制台范围内,不在此问题的范围内.
"M-" mappings work perfectly in MacVim (7.3.53), but that's outside of a console and not in the scope of this question.
我对如何在 Vim、iTerm2 或终端下使这些映射工作感兴趣.
I'm interested in how to make those mappings work in Vim, under iTerm2 or Terminal.
我的规格:
- MAC OS X Lion 10.7.2
- iTerm2 1.0.0.20111020
- vim @7.3.107_0+python26 [通过 MacPorts]
推荐答案
我已经下载了最新的 iTerm2 并试图查看它发送到的内容/Vim 打印的内容 (i<C-v><M-a>
) 具有以下设置:
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:
选项作为选项:
Vim 打印 æ
这在我的法语键盘上是正常的和预期的
Vim prints æ
which is normal and expected on my french keyboard
元选项:
Vim 留在那里,等待某事发生.什么都不打印.如果我依次按下 Option 和 a
,我只会得到 a
.以某种随机顺序按下 Option 和 a
可能会打印 á
,这很奇怪且完全出乎意料.
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.
+ESC 选项:
Vim 打印 ^[a
,意思是转义字符后跟字符 a".
Vim prints ^[a
which means "Escape character followed by the character a".
从这些测试来看,如果没有一些假设的黑魔法,Vim 似乎永远不会收到 <M->
.
From these tests it appears that Vim will never ever receive <M->
without some hypothetical black magic.
如果您坚持使用Option as +ESC",似乎您必须将所有自定义<M-something>
映射更改为<Esc>东西
.这可能有效,但会使用任何非英语语言编写任何类型的散文都变得痛苦.
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.
我的工作:我保持 Option 键不变,这样我就可以轻松地输入像 œ…«»
这样的字符,我使用 <Leader>
(映射到 ,
,请参阅 :help mapleader
) 以了解我的所有自定义映射.
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
这篇关于“M-"iTerm2/Terminal 上的 vim 绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!