在 Windows 上以 Vi 模式使用 Python shell

Bri*_*eal 6 python windows vi readline

我知道您可以在类 Unix 操作系统上以 Vi 模式使用 Python shell。例如,我在我的以下行中~/.inputrc

set editing-mode vi
Run Code Online (Sandbox Code Playgroud)

这让我可以在 Python shell 中使用 Vi 风格的编辑。

但是当在 Windows XP 机器上使用 Python 时,这可以工作吗?我使用的是直接从 python.org 下载的适用于 Windows 的预构建 Python。

我猜 Windows 版本不使用 GNU Readline 库,但我很高兴被证明是错误的。:)

Wil*_*ord 4

安装PyReadline

按照 PyReadline 说明设置您的pyreadlineconfig.ini和文件。PYTHONSTARTUPFILE

然后将以下内容添加到您的pyreadlineconfig.ini文件中:

set_mode("vi")
history_filename("~/.pythonhistory")
history_length(200)
Run Code Online (Sandbox Code Playgroud)

历史设置必须在模式设置之后。

现在可以使用诸如ESC K跳转到上一个命令之类的命令。