Mac OS X 终端中的 Vim:逐字移动光标
我已按照 OS X 中的指导进行操作终端逐字移动光标? 现在在终端中我可以逐字移动光标。
然而,在 Vim 中,我只能逐字向后移动。无论我将 \033f 设置为 option+cursor-right
还是 shift+cursor-right
,我都无法逐字前进。我想到的唯一解决方法是进入正常模式并单击
移动到下一个单词。知道如何解决这个问题吗?谢谢。
I have followed the guidance in Is there any way in the OS X Terminal to move the cursor word by word? and now in terminal I can move cursor word by word.
However, in Vim, I am only able to move backward word by word. I cannot move forward word by word, no matter I set \033f to option+cursor-right
or shift+cursor-right
. The only workaround I figured out is to go to normal mode and click <w>
to move to next word. Any idea about how to fix that? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
w
不是解决方法。这是逐字移动的主要方式(另请参见:W
、b
、B
、e
、<代码>E)。您想要的是一种根本无法帮助您学习 Vim 的解决方法。w
is not a workaround. It's the primary way to move word by word (see also:W
,b
,B
,e
,E
). What you want is a workaround that won't help you learn Vim at all.有些人可能会认为使用 VIM 本机键盘快捷键 移动并不是一种解决方法,但对我来说当然既非常不方便又非常低效。特别是您需要在插入模式和正常模式之间切换才能移动到下一个单词的部分。
这就是为什么我想出了一个基于 这个答案关于超级用户。这个想法是将
Terminal.app
提供的输入直接映射到 VIM 中。 SU 上的答案显示了要在vimrc
文件中放入哪些内容,以使 Home/End 键按预期工作。我的以下调整版本包括单词上的
Option+arrow
(或Alt+arrow
)导航。我试图尽可能模仿终端移动的行为。因此,按Option+Right
(Alt+Right
) 会将插入符号移动到单词后的下一个字符(而不是单词的最后一个字符,即 VIM < code>w 本机行为)。这是一个虽小但很重要的好处,您无需退出
插入
模式即可获得Home/End导航。在10.8.5
上测试。Some may argue that moving around with VIM native keyboard shortcuts is not a workaround, but for me it sure is both very inconvenient and very inefficient. Especially the part where you need to switch between
insert
mode andnormal
mode just to move to the next word.That's why I came up with a solution based on this answer on SuperUser. The idea is to map input provided by the
Terminal.app
directly in VIM. The answer on SU shows what to put into yourvimrc
file for the Home/End keys to work as expected.My tweaked version below includes the
Option+arrow
(orAlt+arrow
) navigation on words. I've tried to mimic the behavior of Terminal's moving around as close as I could get. So pressingOption+Right
(Alt+Right
) will move the caret to the next character after the word (as opposed to the last character of the word, which is VIMsw
native bahavior).As a small, but significant bonus you get Home/End navigation without exiting the
insert
mode. Tested on10.8.5
.让我为你澄清一些事情。 Bash(在终端内运行的 shell 程序)具有您所习惯的行为。 (使用 Alt+f 向前移动一个单词,使用 Alt+b 向后移动一个单词。)这最初是为了像 Emacs 那样做的。您可以使用该命令
切换到 vim 行为。在此模式下,您可以使用 Esc 切换到普通模式,并像在 vim 中一样移动;然后按 i 返回插入模式。
因此,如果 Vim 没有尝试像 Emacs 那样行事,请不要感到惊讶。 vim 背后的全部力量就在于这些简单的动作。
Let me clear a few things up for you. Bash (the shell program running inside the terminal) has the behavior you are used to. (Using Alt+f to move forward by word, and Alt+b to move backward by word.) This was originally done to be like Emacs. You can use the command
to switch to vim behavior. In this mode, you can use Esc to switch to normal mode, and move around like in vim; then press i to go back to insert mode.
So don't be surprised that Vim isn't trying to act like Emacs. The whole power behind vim lies behind these simple motions.
截至 11 月 23 日,这些简单的快捷方式对我来说适用于在终端应用程序中打开 vim(插入模式)。这可以 OOTB 运行,不需要编辑 rc 文件等。
Shift+left/right
- 逐字移动Fn+Shift+left/right
- 跳转到行首或行尾Fn+Shift+up/down
- 向上翻页/向下翻页As of Nov'23, these simple shortcuts work for me with vim (insert mode) open in Terminal app. This works OOTB, no editing of rc files etc. is needed.
Shift+left/right
- move word by wordFn+Shift+left/right
- jump to beginning or end of the lineFn+Shift+up/down
- page up/page down