Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When in Readline apps with vim mode enabled in ~/.inputrc (set editing-mode vi) is there a way to bind the <Up> arrow key in vi-insert mode? To display previous history item, for example. It seems I have to press ESC key first, only then it works.

Here's my attempt at making it work (~/.inputrc):

$if mode=vi
  # INSERT MODE
  set keymap vi-insert
  "\e[A": history-search-backward # up-arrow
  "\e[B": history-search-forward  # down-arrow

Also note, that when I press Ctrl+v and then <Up>, it prints ^[[A.

I did manage to have it working like I want in zsh: http://paulgoscicki.com/archives/2012/09/zsh-vi-mode-with-emacs-keybindings/

share|improve this question
add comment

1 Answer

What you want works in bash already: I can use up-arrow to display the previous history item in vi-insert mode. The following command shows how it is configured. Perhaps you are confusing history-search-backward with 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)
share|improve this answer
    
You're confusing READLINE with shell. I have no problems configuring the desired behaviour in my shell of choice, which is zsh. I have problems with Readline apps, like Postgresql console, IRB, etc. –  Paweł Gościcki Oct 18 '12 at 21:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.