Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Python shell in Vi mode on Windows

I know that you can use the Python shell in Vi mode on Unix-like operating systems. For example, I have this line in my ~/.inputrc:

set editing-mode vi

This lets me use Vi-style editing inside the Python shell.

But can this be made to work when using Python on a Windows XP box? I'm using the pre-built Python for Windows downloaded directly from python.org.

I'm guessing that the Windows version does not use the GNU Readline library, but I'd be happy to be proven wrong. :)

like image 962
Brian Neal Avatar asked Dec 03 '09 04:12

Brian Neal


People also ask

How do I set bash to vi mode?

The bash shell (again, via GNU Readline) is able to provide this functionality for us. In order to enable it, you run the command $ set -o vi.


2 Answers

Install PyReadline

Setup your pyreadlineconfig.ini and PYTHONSTARTUPFILE files as per the PyReadline instructions.

Then add the following to your pyreadlineconfig.ini file:

set_mode("vi")
history_filename("~/.pythonhistory")
history_length(200)

The history settings must be after the mode setting.

Commands such as ESC K to jump to the previous command now work.

like image 136
William Bettridge-Radford Avatar answered Oct 02 '22 06:10

William Bettridge-Radford


cygwin can give you many Unix-y advantages on your "Windows XP box" (using its own Python build, among other things -- avoiding some of the Windows-only limitations of the "standard Windows builds") -- try it out!

like image 40
Alex Martelli Avatar answered Oct 02 '22 08:10

Alex Martelli