[英]How to get Cmd-left/right working with iTerm2 and Vim (without requiring .vimrc changes)?
I want to be able to use Option-left and Option-right to skip words (and Cmd-left/right to go to beginning and end of lines) within Vim as it does at my shell prompt.我希望能够使用 Option-left 和 Option-right 在 Vim 中跳过单词(和 Cmd-left/right 转到行的开头和结尾),就像在我的 shell 提示符下一样。 My Iterm2 preferences have mappings to do this (eg Option-left
to Esc-H
and a one for option-right
to Esc-F
to skip over words), and this works in the shell locally or when ssh'd to a remote server.我的 Iterm2 首选项有映射来执行此操作(例如Option-left
到Esc-H
和一个option-right
到Esc-F
以跳过单词),这在本地 shell 中或当 ssh 到远程服务器时有效.
When I use Vim locally or remotely, option-left
works, but option-right
does not.当我在本地或远程使用 Vim 时, option-left
有效,但option-right
无效。 I suspect this is because Vim naturally listens for Esc-H
, but not Esc-F
.我怀疑这是因为 Vim 自然会监听Esc-H
,而不是Esc-F
。 I am able to get around this by modifying .vimrc file to Esc-b
to b
and Esc-f
to f
, but I don't want to do this to every server I'm connecting to.我可以通过将 .vimrc 文件修改为Esc-b
到b
和Esc-f
到f
来解决这个问题,但我不想对我连接的每个服务器都这样做。
Similarly, I have the same desired setup for Cmd-left/right for going to beginning and end of a line.同样,我对 Cmd-left/right 有相同的所需设置,用于转到行的开头和结尾。 I can get this working in the shell via Iterm2 mappings (eg Cmd-left
to Esc-[h
), but Vim doesn't respond at all to this unless I map keys again (eg Esc-[h
to ^
).我可以通过 Iterm2 映射(例如Cmd-left
到Esc-[h
)在 shell 中实现它,但是除非我再次映射键(例如Esc-[h
到^
),Vim 根本不会对此做出响应。
Update: I just figured out how to get option-left/right working.更新:我刚刚想出了如何让 option-left/right 工作。 I changed mapping in iTerm2 for these to be escape-[1;5D
and escape-[1;5C
respectively.我将 iTerm2 中的映射分别更改为 escape- escape-[1;5D
和escape-[1;5C
。 I still want to solve the Cmd-left/right problem though (I changed my question's title to reflect this).我仍然想解决 Cmd-left/right 问题(我改变了我的问题标题以反映这一点)。 Any ideas?有任何想法吗?
To mimic OS X's behavior of sending Cmd-left/right
to the beginning/end of a line, I add the following mappings in iTerm2:为了模仿 OS X 将Cmd-left/right
发送到行首/尾的行为,我在 iTerm2 中添加了以下映射:
Cmd-left
to escape-sequence [1~
Cmd-left
转义序列[1~
Cmd-right
to escape-sequence [4~
Cmd-right
转义序列[4~
To mimic OS X's behavior of sending Option-left/right
to the previous/next word, I add the following mappings in iTerm2:为了模仿 OS X 将Option-left/right
发送到上一个/下一个单词的行为,我在 iTerm2 中添加了以下映射:
Option-left
to escape-sequence [1;5D
Option-left
转义序列[1;5D
Option-right
to escape-sequence [1;5C
转义序列的Option-right
[1;5C
Special thanks to this blog post for tracking down what I was missing with the cmd-left/right
mappings特别感谢这篇博文追踪我在cmd-left/right
映射中遗漏的内容
FWIW, dolan's answer didn't work for me on iTerm 2 1.0.0.20120203 on Mac OS X 10.7.3. FWIW,在 Mac OS X 10.7.3 上的 iTerm 2 1.0.0.20120203 上,dolan 的回答对我不起作用。 His solution only inserted ~
and 5D
/ 5C
into my terminal when I pressed the shortcut keys.当我按下快捷键时,他的解决方案仅将~
和5D
/ 5C
插入到我的终端中。
Instead, I used the following solutions:相反,我使用了以下解决方案:
Cmd-left/right
: iTerm 2: How to set keyboard shortcuts to jump to beginning/end of line? Cmd-left/right
: iTerm 2: 如何设置键盘快捷键跳转到行首/行尾?
Option-left/right
as well as option-delete
: http://hackaddict.blogspot.co.at/2007/07/skip-to-next-or-previous-word-in-iterm.html Option-left/right
以及option-delete
: http : //hackaccident.blogspot.co.at/2007/07/skip-to-next-or-previous-word-in-iterm.html
YMMV, not sure why one set of solutions would work and not the other YMMV,不确定为什么一组解决方案有效,而另一组无效
I don't have MacOS, so I cannot exactly know your situation, but I recognize the problem from other OSes.我没有 MacOS,所以我不能确切地知道你的情况,但我认识到其他操作系统的问题。
Basically, it would mean that the terminal sends keycodes that aren't understood by vim.基本上,这意味着终端发送 vim 无法理解的键码。 I fixed it in the past by doing我过去通过做修复了它
TERM=something
export TERM
before invoking vim在调用 vim 之前
Eg in order to get all keys and syntax highlighting working on AIX 5.3 across Putty/screen, I needed to use例如,为了在 AIX 5.3 上通过 Putty/screen 获得所有键和语法突出显示,我需要使用
TERM=iris-ansi vim
There is a list of builtin terminal types if you pass a bad TERM如果您传递了错误的 TERM,则有一个内置终端类型列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.