Using the Python shell in Vi mode on Windows

前提是你 提交于 2020-01-14 13:14:37

问题


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. :)


回答1:


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.




回答2:


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!




回答3:


Answering my own question, it looks like you can use the PyReadline library in conjunction with IPython to get most of the Vi functionality I miss on Linux. I still haven't figured out how I can hit ESC and then k to scroll through the previous command history.



来源:https://stackoverflow.com/questions/1837693/using-the-python-shell-in-vi-mode-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!