Use vi key bindings in bash

A long time ago I used ksh with vi key bindings, and life was good.

Then I moved on to bash, but for some reason, I never investigated using vi key bindings. I simply lived with the defaults (which, for the record, are emacs-like key bindings).

So, just the other day I said to myself, “Self, I want to use vi key bindings in bash. I want to again experience the joy of traversing and editing my command line in COMMAND MODE. I want the speed and the power of my precious vi (well, I use vim) at my finger tips. And I NO LONGER want to waste time holding arrow keys or to think about using emacs-like commands.”

So, I fired up google.com; low and behold I stumbled onto this little post about using vi key bindings in bash and zsh. So sweet!

In a nutshell, the bash command to enable vi mode is:

set -o vi

This can be set in your .bashrc file, and if it doesn’t pickup when you start a new terminal session, add something like this to your .profile or .bash_profile:

if [ -f ~/.bashrc ]; then<br /> . ~/.bashrc<br /> fi

With vi mode enabled, you’ll start your bash session in insert mode, so things should behave as normal. But, to turn on the power, just hit the ESC key to enter COMMAND MODE. 🙂 Now all your vi commands are availble. Move to end of line with “$”, beginning of line with “^”, delete a word with “dw”, etc.

Enjoy!