Take the 2-minute tour ×
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.

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
add comment

1 Answer

up vote 6 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
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.