Monday, June 15, 2009

Vi Mode in Readline Applications

Mike Pea submitted this comment in a recent tip, and I thought it deserved it's own post.

If you find that you do like using vi editing mode (and what's not to love about it :), add 'set editing-mode vi' to your .inputrc, and vi mode will work in any readline based client, eg psql, irb.

Thanks Mike!

7 comments:

MattBD said...

Does that work in the Python interactive shell? I would love to be able to use vi mode for that!

GGLucas said...

Yes, it does work in Python, actually.
Readline is awesome.

Tomasz said...

in short -- set -o vi

it works with ksh, bash for sure, not sure if that's a terminal mode, i would assume it's a kornshell feature.

one disadvantage is that you actually do have to work with line in vi mode. takes some time before you get used to that...

of course it's a vi-mode editing not vim-mode editing, so don't even count on many of your favourite keystrokes...

Chris said...

I prefer ctrl-x ctrl-e

Travis Whitton said...

@Chic

Actually set -o vi is used to control shell behavior while this tip is about controlling command-line editing in readline applications.

Readline applications are programs that link against GNU readline and allow text modification similar to modern interactive shells. Examples would be: irb, mysql client, python, and many others.

Unknown said...

Great tip! I've been fussing with irb, wishing there was a way of utilizing my vi fingers....

Unknown said...

This is huge!

I've been using set -o vi on the command line for a while and it's a huge productivity boost.

I was always frustrated working with the mysql (especially), irb, python shell etc, having to use up arrows/backspace and 'stepping through' history and commands)

What is so cool about this is you can edit your history as well, so especially for long mysql queries, you can Esc-k, k, b, b, b, edit a word and hit enter, wala

I just confirmed, Centos 5.3, mysql, irb, python shell, unfortunately does not work on the cpan shell. (I guess it doesn't' use readline, not that big a deal)

Many thanks.

(do you know about the firefox vi plugin? http://vimperator.org/trac/wiki/Vimperator I'm not used to it yet but it seems cool)