如何在 ~/.inputrc (readline) 中绑定向上箭头以用于 vim 插入模式?

如何在 ~/.inputrc (readline) 中绑定向上箭头以用于 vim 插入模式?

当在 ~/.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)

相关内容