Icon_search
Colin

Bash modes

Posted on 01/06/2009 by Colin
 | 

I've been using Bash for years now and have gotten relatively comfortable with the Emacs-based commands necessary to navigate around a previously entered command that needed to be modified. However, I've occasionally encountered cases where I wished that the command line behaved more like vi. Not that I think it's definitively better than Emacs, I just know a bit of vi, and the only Emacs commands I know are the few I've done in some 5-minute tutorial I went through at some point, along with the Bash commands I blogged about in July.

At any rate, my wish apparently came true years ago! Readline, the library that allows you to edit the command line, can be put into vi mode under Bash (and other programs that use Readline). It's easy:

set -o vi

So now you can use the command line pretty much exactly like vi: Esc to get into command mode and use all your favorite vi commands, and the normal commands (i, a, c, etc.) to get back into insert mode and resume typing. If you decide it sucks and want to go back, it's just set -o emacs. Have fun!

Update: I decided it sucks and went back. Maybe you'll like it, though!

Tagged:  bash, readline, vi, emacs