Bash Editing In vi Mode

I was discussing about how some applications have adopted some of the vi key bindings. Like Google Reader, some tiling window managers like xmonad, and even bash has excellent support for editing in vi mode. Surprisingly not many know about this. Hence this post.

Bash supports two editing modes, vi and emacs (which is the default) equally well. So you have to do something more to use the vi editing mode, and that something more is put the following in your .bashrc file.

set -o vi

However, unlike vi, it is by default in the insert mode. However, do not get discouraged, you can use the Esc key to go in the command mode and use the vi key bindings for moving around. It is god-sent when I work with long commands. Additionally, the commands j and k will let you move through the command history. And, here comes the best part, you can use the command v to launch the editor and edit the command in there. I have this habit of concatenating commands in one single line, and before I know it gets unmanageable on the command line. Nothing like being able to seamlessly edit with my favourite editor.

There is a nice cheat sheet available if you are interested in using this. If you are a vi or vim user, this can ease your life a lot.

Discussion [Participate or Link]

  1. vi - The Interface | iface thoughts said:

    […] bash – a Unix shell has vi mode […]

  2. T?? ? Techpot » Blog Archive » VI – The Interface said:

    […] bash – a Unix shell has vi mode […]

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.