如何让 Cmd-left/right 与 iTerm2 和 Vim 一起工作(不需要 .vimrc 更改)? [英] How to get Cmd-left/right working with iTerm2 and Vim (without requiring .vimrc changes)?
问题描述
我希望能够在 Vim 中使用 Option-left 和 Option-right 跳过单词(以及 Cmd-left/right 跳转到行首和行尾),就像在我的 shell 提示符下一样.我的 Iterm2 首选项有映射来做到这一点(例如 Option-left
到 Esc-H
和一个 option-right
到 Esc-F
跳过单词),这适用于本地 shell 或 ssh 到远程服务器时.
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. My Iterm2 preferences have mappings to do this (e.g. 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.
当我在本地或远程使用 Vim 时,option-left
有效,但 option-right
无效.我怀疑这是因为 Vim 自然会监听 Esc-H
,而不是 Esc-F
.我可以通过将 .vimrc 文件修改为 Esc-b
到 b
并将 Esc-f
修改为 f代码>,但我不想对我连接的每台服务器都这样做.
When I use Vim locally or remotely, option-left
works, but option-right
does not. I suspect this is because Vim naturally listens for Esc-H
, but not 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.
同样,我对 Cmd-left/right 有相同的期望设置,用于转到行的开头和结尾.我可以通过 Iterm2 映射(例如 Cmd-left
到 Esc-[h
)让这个在 shell 中工作,但是除非我映射,否则 Vim 根本不响应这个再次键(例如 Esc-[h
到 ^
).
Similarly, I have the same desired setup for Cmd-left/right for going to beginning and end of a line. I can get this working in the shell via Iterm2 mappings (e.g. Cmd-left
to Esc-[h
), but Vim doesn't respond at all to this unless I map keys again (e.g. Esc-[h
to ^
).
更新:我刚刚想出了如何让选项左/右工作.我将 iTerm2 中的映射分别更改为 escape-[1;5D
和 escape-[1;5C
.我仍然想解决 Cmd-left/right 问题(我更改了我的问题标题以反映这一点).有什么想法吗?
Update: I just figured out how to get option-left/right working. I changed mapping in iTerm2 for these to be escape-[1;5D
and escape-[1;5C
respectively. I still want to solve the Cmd-left/right problem though (I changed my question's title to reflect this). Any ideas?
推荐答案
为了模仿 OS X 将 Cmd-left/right
发送到行首/行尾的行为,我添加了以下映射在 iTerm2 中:
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:
Cmd-left
转义序列[1~
Cmd-right
转义序列[4~
Cmd-left
to escape-sequence[1~
Cmd-right
to escape-sequence[4~
为了模仿 OS X 将 Option-left/right
发送到上一个/下一个单词的行为,我在 iTerm2 中添加了以下映射:
To mimic OS X's behavior of sending Option-left/right
to the previous/next word, I add the following mappings in iTerm2:
Option-left
转义序列[1;5D
Option-right
转义序列[1;5C
Option-left
to escape-sequence[1;5D
Option-right
to escape-sequence[1;5C
特别感谢这篇博文的追踪我在 cmd-left/right
映射中遗漏了什么
Special thanks to this blog post for tracking down what I was missing with the cmd-left/right
mappings
这篇关于如何让 Cmd-left/right 与 iTerm2 和 Vim 一起工作(不需要 .vimrc 更改)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!