![如何在 ~/.inputrc (readline) 中绑定向上箭头以用于 vim 插入模式?](https://linux22.com/image/1333111/%E5%A6%82%E4%BD%95%E5%9C%A8%20~%2F.inputrc%20(readline)%20%E4%B8%AD%E7%BB%91%E5%AE%9A%E5%90%91%E4%B8%8A%E7%AE%AD%E5%A4%B4%E4%BB%A5%E7%94%A8%E4%BA%8E%20vim%20%E6%8F%92%E5%85%A5%E6%A8%A1%E5%BC%8F%EF%BC%9F.png)
当在 ~/.inputrc ( ) 中启用 vim 模式的 Readline 应用程序中,set editing-mode vi
是否有办法<Up>
在vi-insert
模式中绑定箭头键?例如,显示上一个历史记录项。似乎我必须先按 ESC 键,然后它才能起作用。
以下是我使其工作的尝试(〜/ .inputrc):
$if mode=vi
# INSERT MODE
set keymap vi-insert
"\e[A": history-search-backward # up-arrow
"\e[B": history-search-forward # down-arrow
另请注意,当我按下Ctrl+v
然后按下时<Up>
,它会打印^[[A
。
我确实设法让它在 zsh 中按我想要的方式工作: http://paulgoscicki.com/archives/2012/09/zsh-vi-mode-with-emacs-keybindings/
答案1
您想要的已经起作用了bash
:我可以使用向上箭头在 vi-insert 模式下显示上一个历史记录项。以下命令显示了它的配置方式。也许您history-search-backward
对感到困惑history-prev
?
$ bind -m vi-insert -p | grep hist
# beginning-of-history (not bound)
# dynamic-complete-history (not bound)
# end-of-history (not bound)
"\C-s": forward-search-history
# history-and-alias-expand-line (not bound)
# history-expand-line (not bound)
# (not bound)
# history-search-forward (not bound)
"\eOB": next-history
"\e[B": next-history
# non-incremental-forward-search-history (not bound)
# non-incremental-forward-search-history-again (not bound)
# non-incremental-reverse-search-history (not bound)
# non-incremental-reverse-search-history-again (not bound)
"\eOA": previous-history
"\e[A": previous-history
"\C-r": reverse-search-history
# vi-fetch-history (not bound)