在 Windows 上以 Vi 模式使用 Python shell

发布于 2024-08-13 06:19:10 字数 326 浏览 5 评论 0原文

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

set editing-mode vi

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哽咽笑 2024-08-20 06:19:10

安装 PyReadline

设置您的 pyreadlineconfig.iniPYTHONSTARTUPFILE< /code> 按照 PyReadline 说明文件。

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

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

历史设置必须位于模式设置之后。

现在可以使用 ESC K 等命令跳转到上一个命令。

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.

神回复 2024-08-20 06:19:10

cygwin 可以为您的“Windows XP 盒子”提供许多 Unix-y 优势(使用它自己的 Python 构建,除其他事项外 - 避免“标准 Windows 版本”的一些仅限 Windows 的限制) - 尝试一下!

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!

等风也等你 2024-08-20 06:19:10

回答我自己的问题,看起来您可以将 PyReadline 库与 IPython 来获得我在 Linux 上怀念的大部分 Vi 功能。我仍然不知道如何按 ESC 然后按 k 滚动浏览上一个命令历史记录。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文