Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just discovered the wonders of set -o vi, and am curious if it is possible to customize this vi shell mode in some of the same ways you can customized vi or vim?

For example, create a custom key binding to map a more convenient key or key combo to esc?

If it's not currently supported, how difficult would it be to alter the source code of the program and hardcode in some customizations, or would that be a bad idea?

share|improve this question
I found answer in here <unix.stackexchange.com/questions/27699/remap-bash-vi-keys>; – DinizBr Jun 3 at 2:30
@DinizBr, I love you! – Jonah Jun 3 at 3:14
up vote 9 down vote accepted

Yes, you can change key mappings (for either vi- or emacs-like mode) with the bind builtin. This is actually a readline feature (so you can have vi-like bindings in all readline programs, not just bash).

The key you're looking for is called vi-movement-mode, and defaults to \e (escape). You could additionally bind it to (and this is rather silly) equals like this. The second line gets rid of the binding to escape:

$ bind "=":vi-movement-mode 
$ bind -r "\e"

Running bind -p will show you all the keys you can bind, and their current bindings (if any).

You can put bind commands in your .bashrc, or you can edit ~/.inputrc to make it apply to all readline programs you run. The readline docs contain full details.

share|improve this answer
This is awesome. Thanks so much. I was able to figure out how to bind key combos like bind "Control-Space":vi-movement-mode -- that works fine. But for example in vim I have typing two characters in a row as trigger to esc, ie, if you type jj you'll return to normal mode. This did not work when I tried it with bind, is there a special way to make it work? – Jonah Apr 29 '13 at 19:15
@Jonah not that I know of off-hand, but I haven't perused the readline docs recently... – derobert Apr 29 '13 at 19:26
@chishaku you need to prefix Jonah's name with an at sign (@), or he won't get a notification. – derobert Nov 24 '14 at 21:31
@Jonah I just tried to do the same thing. Did you ever figure this out? – chishaku Nov 24 '14 at 21:41
@derobert Thanks! – chishaku Nov 24 '14 at 21:42

Your Answer


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.