tags:

views:

827

answers:

2

Hi, this is going to sound pretty ignorant, but:

I was working a bit in the python interpreter (python 2.4 on RHEL 5.3), and suddenly found myself in what seems to be a 'vi command mode'. That is, I can edit previous commands with typical vi key bindings, going left with h, deleting with x...

I love it - the only thing is, I don't know how I got here (perhaps it's through one of the modules I've imported: pylab/matplotlib?).

Can anyone shed some light on how to enable this mode in the interpreter?

+11  A: 

This kind of all depends on a few things.

First of all, the python shell uses readline, and as such, your ~/.inputrc is important here. That's the same with psql the PostgreSQL command-line interpreter and mysql the MySQL shell. All of those can be configured to use vi-style command bindings, with history etc.

<ESC> will put you into vi mode at the python shell once you've got your editing mode set to vi

You may need the following definition in your ~/.inputrc

set editing-mode vi
Phil
did a line in your answer go missing, just before "will put you..."? thanks!
yungchin
I've fixed a formatting bug before "will put you..."
J.F. Sebastian
Wow. Not only did I not know this, I didn't even know there was anything there to know!
John Fouhy
Thanks, both for the answer and for fixing the missing ESC in it. This is great info, but I'm accepting arcanex' answer because it explains what happened in my mysterious case... (I didn't have any .inputrc file)
yungchin
I hope you'll pardon my French, but you are my fucking hero.
chaos
+7  A: 

Ctrl-Alt-J switches from Emacs mode to Vi mode in readline programs.

Doesn't work for me -- just seems to produce a <return>. I'm on a mac; does that make a difference?
John Fouhy
Works here! Don't know about Macs I'm afraid...
yungchin
For anyone having enough rep to add to this answer, here's a link to the readline docs: http://tiswww.case.edu/php/chet/readline/rluserman.html#SEC22 ...so for emacs-editing-mode hit C-e, and for vi-editing-mode hit M-C-j
yungchin