在 Windows 上以 Vi 模式使用 Python shell [英] Using the Python shell in Vi mode on Windows

查看:53
本文介绍了在 Windows 上以 Vi 模式使用 Python shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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.

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

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

推荐答案

安装 PyReadline

按照 PyReadline 说明设置您的 pyreadlineconfig.iniPYTHONSTARTUPFILE 文件.

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

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

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.

诸如 ESC K 之类的命令现在可以跳转到上一个命令了.

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

这篇关于在 Windows 上以 Vi 模式使用 Python shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆