2014-04-16 Python vi keybindings on OS X

Last edit

Summary: If you're used to vi keybindings, and you use Python interactively, you're going to do a lot of cursing on OS X. This is because the readline library . . .

Changed:

< Here's a quick fix:
< * add
a file called .editrc with the following content:

to

> Here's a quick fix.
> Add
a file called .editrc with the following content:

Changed:

< * add a file called .pythonrc with the following lines:

to

> Add a file called .pythonrc with the following lines:

Changed:

< * add a line to your .bashrc which makes Python run .pythonrc when it starts interactively:

to

> Add a line to your .bashrc which makes Python run .pythonrc when it starts interactively:

Changed:

< Start python from the commandline and voilà, enjoy history and vi keybindings and all that good stuff.

to

> Start python from the commandline and voilà, enjoy history and vi keybindings and all that good stuff. Tested on 10.9.2 (Mountain Lion).


If you're used to vi keybindings, and you use Python interactively, you're going to do a lot of cursing on OS X. This is because the readline library (responsible for keybindings and history) is GPL licensed and thus not distributed by Apple.

Here's a quick fix.

Add a file called .editrc with the following content:

 bind -v

Add a file called .pythonrc with the following lines:

 import rlcompleter
 import readline

Add a line to your .bashrc which makes Python run .pythonrc when it starts interactively:

 export PYTHONSTARTUP="$HOME/.pythonrc"

Start python from the commandline and voilà, enjoy history and vi keybindings and all that good stuff. Tested on 10.9.2 (Mountain Lion).