vi 模式下的 Bash:使用光标向上/向下浏览 shell 历史记录,光标位置不在末尾?
我非常喜欢 vim,并且真的很想通过 vi-mode 增强我的 bash 体验。 然而,我非常习惯 emacs 的行为,因为当使用向上/向下光标浏览 shell 历史记录时,光标位于行尾。
在 vi 模式下,情况正好相反; 光标始终位于行的开头。 在 emacs 模式下使用 bash 已经太久了,期待光标出现在最后真的让我的大脑很痛苦。
当浏览 shell 历史记录时,是否有机会在 bash vi 模式下默认获取光标位置?
I'm very fond of vim and really would like to enhance my bash experience with vi-mode. However one thing I'm so accustomed to the emacs behavior in that, when browsing the shell history with cursor up/down, the cursor is positioned at the end of the line.
In vi-mode it's the other way around; the cursor is always positioned at the beginning of the line. It's really burned in the brain to expect the cursor at the end, having used bash in emacs mode for ... way too long.
Any chance to get the cursor position by default at the end of the line in bash vi-mode when browsing through the shell history?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要重新映射向上和向下光标:
这会将上一个历史记录、下一个历史记录和行尾映射到不存在的键,然后向上和向下映射到这些字符的序列。 如果你愿意的话,你可以对 j/k 做同样的事情,但我建议不要管它们。 这样你就可以两者兼得。
这仅在您处于命令模式时重新映射按键。 在我的机器上,在插入模式下光标已经位于行尾。 如果这不适合您,您可以使用 vi-insert 而不是 vi-command 作为键盘映射来执行相同的操作。
You need to remap the up and down cursors:
This will map previous-history, next-history and end-of-line to non-existant keys, then map up and down to a sequence of those characters. You can do the same for j/k if you want, but I'd recommend leaving them alone. That way you can do both.
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.
我不知道有什么方法可以在
bash
(或者readline
,实际上)中重新编码历史代码。然而,一旦您找到要在末尾开始附加的行,输入
Shift-A
真的那么难吗?如果您打算放弃 emacs 模式,那么在某个时候,您将必须完全放弃 emacs 模式并接受
vi
的处理方式。 加入我们,您知道您想要:-)I don't know of a way of doing this short of re-coding the history code inside of
bash
(orreadline
, really).However, is it really so hard to enter
Shift-A
once you've found your line to start appending at the end?If you're going to ditch emacs mode then, at some point, you're going to have to do it totally and accept the
vi
way of doing things. Join us, you know you want to :-)