"M-"表示在iTerm2/Terminal上的vim绑定不起作用 [英] "M-" bindings in vim on iTerm2/Terminal don't work
问题描述
我注意到 iTerm2 提供了使用"Option键作为+ ESC"(或元,但显然已经过时了).
我都尝试了这两个选项,并且选项键在Bash(set -o emacs
模式)和Emacs中可以正常工作,但在Vim中却没有.因此,我无法使用任何"M-"绑定.
我发现的是:
- 如果我将选项设置为"+ ESC",则vim会理解ESC +键,并且不知道我的意思是Meta-key.
- 如果我将option设置为"meta",则用"option"修改的键的行为就像没有修饰符一样(不知道如何正式测试vim从我输入的键组合中了解什么).
"M-"映射在MacVim(7.3.53)中可以完美地工作,但这在控制台之外,不在此问题的范围内.
我对如何使这些映射在iTerm2或Terminal下的Vim中工作感兴趣.
我的规格:
- 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>
)打印的内容/的内容:>
-
作为选项的选项:
Vim打印
æ
,这在我的法语键盘上是正常且预期的 -
作为元数据的选项:
Vim待在那儿,等着事情发生.什么都没有打印.如果我依次按Option键和
a
键,则只需获取a
即可.按任意顺序按Option和a
可能会打印á
,这很奇怪,而且完全是意外的. -
作为+ ESC的选项:
Vim打印
^[a
,表示转义字符后跟字符a".
从这些测试看来,如果没有一些假设的黑魔法,Vim将永远不会收到<M->
.
如果您坚持使用"Option as + ESC" ,似乎您必须将所有自定义<M-something>
映射更改为<Esc>something
.这可能行得通,但会使使用任何非英语语言撰写任何类型的散文都感到痛苦.
我的工作:我保持Option键不变,以便我可以轻松键入œ…«»
之类的字符,并为所有自定义映射使用<Leader>
(映射到,
,请参见:help mapleader
).
这里有些人喜欢为插件保留它,并提倡一种更简单且可能更安全的方法.
inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
inoremap ,, <C-x><C-o> "another way
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]
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 keyboardOption as Meta:
Vim stays there, waiting for something to happen. Nothing is printed. If I press Option and
a
in sequence I just obtaina
. Pressing Option anda
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
这篇关于"M-"表示在iTerm2/Terminal上的vim绑定不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!