3

我非常喜欢 vim,并且真的很想通过 vi-mode 增强我的 bash 体验。然而,我非常习惯于 emacs 行为的一件事是,当使用光标向上/向下浏览 shell 历史记录时,光标位于行尾

在 vi 模式下则相反;光标始终位于行首。在 emacs 模式下使用 bash 的时间太长了,期待光标在末尾真的很烧脑。

浏览 shell 历史记录时,是否有机会在 bash vi 模式下默认获取光标位置?

4

2 回答 2

6

您需要重新映射上下光标:

bind -m vi-command '"\201": previous-history'
bind -m vi-command '"\202": next-history'
bind -m vi-command '"\203": end-of-line'
bind -m vi-command '"\e[A": "\201\203"'
bind -m vi-command '"\e[B": "\202\203"'

这会将上一个历史、下一个历史和行尾映射到不存在的键,然后上下映射到这些字符的序列。如果你愿意,你可以对 j/k 做同样的事情,但我建议不要管它们。这样你就可以两者兼得。

This only remaps the keys when you are in command mode. On my machine, the cursor is already at the end of the line in insert mode. If this is not true for you, you can do the same using vi-insert instead of vi-command as the keymap.

于 2009-05-13T10:01:26.217 回答
5

我不知道如何在bash(或者readline,真的)内部重新编码历史代码。

但是,一旦找到要在末尾添加的行,就真的很难输入吗?Shift-A

如果您要放弃 emacs 模式,那么在某些时候,您将不得不完全这样做并接受vi做事的方式。加入我们,你知道你想:-)

于 2009-05-10T07:44:59.893 回答