Normally, I use vi mode in bash. It starts off in insert mode you have to hit Esc (or Altj was it?) to get into normal (command) mode.

I also bind (up-arrow) to history-search-backward.

What I'd like is to make it so that when I hit up arrow, not only does it do the history-search-backward, but also sets me to normal mode. (Sort of like tcsh behaves.)

I found a lot of related posts and people who have done clever things in .inputrc, but nothing quite like what I'm after here. (Like this and this in particular.)

Is this possible in bash?


1 Answer 1



bind -m vi-move '"\e[A": history-search-backward'
bind -m vi-insert '"\e[A": " \e\e[A"'

(assuming that the Up key is sending a \e[A escape)

I don't think that's possible other than by (indirectly) binding keys to macros.

  • Thanks. That seems to work perfectly. The only other thing I had to do was change: bind -m vi-insert '"\e[B": history-search-forward' ...to... bind -m vi-command '"\e[B": history-search-forward' ...in order to get the down arrow key to work properly. Jul 5, 2019 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .