控制台中的IPython 5.0和按键绑定 [英] IPython 5.0 and key bindings in console

查看:84
本文介绍了控制台中的IPython 5.0和按键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新版本的IPython不再依赖readline,而是使用纯Python库prompt-toolkit,解决了Apple和Windows系统上的维护问题.

The new release of IPython does not depend any more on readline but uses the pure Python library prompt-toolkit, solving maintenance problems on Apple's and Windows' systems.

一项新功能是能够编辑多行代码块,使用光标键在代码块中自由移动-这种功能至少对我来说是一个问题:因为 ret 在代码中插入新行,要将整个块传递给解释器,您必须使用快捷键 alt + ret 或可能不太方便的键序列 esc ,然后是 ret .

A new feature is the ability to edit a multi-line code block, using the cursor keys to move freely in the code block — with this power it comes, at least for me, a problem: because a ret inserts a new line in your code, to pass the whole block to the interpreter you have to use the shortcut alt+ret or possibly the less convenient key sequence esc followed by ret.

我说,这是一个问题,因为我选择的终端仿真器是XTerm,并且在许多Linux发行版中,快捷方式 alt + ret 没有传递给该应用程序,但供运行IPython的XTerm直接用于切换该终端的屏幕填充度(@ ThomasDickey,xterm的管理者和合著者指出,默认情况下,xterm不在意发送对于应用程序,即使取消绑定全屏"操作,也要在Enter上添加修饰符位.

I say, this is a problem, because my terminal emulator of choice is the XTerm and, on many Linux distributions, the shortcut alt+ret is not passed to the application but it is directly used by the XTerm in which IPython is running, to toggle the screen-fullness of the said terminal (@ThomasDickey, xterm's mantainer and co-author pointed out that, by default, xterm doesn't care to send to the application the modifier bit on Enter even when one unbinds the Fullscreen action).

由于这个原因,我想至少修改此特定的IPython按键绑定.

For this reason I'd like to modify at least this specific IPython key binding.

我发现了IPython的先前版本(基于readline的版本)的说明(某种),不适用于新的5.0版本.

I've found instructions (sort of) for the previouos versions, the readline based ones, of IPython that do not apply to the new, 5.0 version.

我需要的是可以引导我在IPython的用户文档中找到我可以绑定的可能动作的名称,与动作绑定的快捷方式的名称以及配置新的步骤.键绑定.

What I would need are instructions that lead me to find, in IPython's user documentation, the names of the possible actions that I can bind, the names of the shortcuts to bind with the actions and the procedure to follow to configure a new key binding.

如果没有这种类型的规范答案,我可能对配方完成此特定的键绑定感到满意,条件是该配方仍可在IPython 6.0中使用

Failing to have this type of canonical answer, I may be happy with a recipe to accomplish this specific keybinding, with the condition that the recipe still works in IPython 6.0

推荐答案

您可以更改xterm的配置.

You could change xterm's configuration.

xterm是可配置的(并记录在案).在xterm手册中, 默认键绑定 部分显示了此键的默认绑定:

xterm is configurable (and documented). In the xterm manual, the Default Key Bindings section shows the default binding for this key:

                        Alt <Key>Return:fullscreen() \n\

您可以通过多种方式抑制该绑定:

You can suppress that binding in more than one way:

  • 使用 omitTranslation 资源隐藏该功能
  • fullscreen 资源设置为 never

但是,仅仅抑制它不会使它发送一些有趣的东西(xterm会忽略 Enter 的修饰符).设置 translation 资源的工作原理例如在您的$HOME/.Xdefaults文件中:

However, just suppressing it will not make it send something interesting (xterm ignores the modifier for Enter). Setting a translation resource works, e.g., in your $HOME/.Xdefaults file:

*VT100*translations:      #override \n\ 
     Alt <Key>Return: string("\033[27;3;13~")

这篇关于控制台中的IPython 5.0和按键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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