iPython不读取~/.inpu

2024-09-28 22:35:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在用iPython。文档说我应该能够使用inputr重新映射readline库的键。以下是我的输入:

set editing-mode emacs
set keymap emacs
Meta-h: backward-word
Meta-s: forward-word
Control-h: backward-char
Control-s: forward-char
Control-n: previous-history
Control-t: next-history
Control-p: yank
Meta-p: yank-pop

当我加载iPython时,这些映射根本不起作用。我在OSX10.9Mavericks上。我没有看到任何关于使用libedit而不是readline的警告。有什么想法吗?在


Tags: 文档readlineipythonhistorymetacontrolwordforward
2条回答

IPython Documentation

All these features are based on the GNU readline library, which has an extremely customizable interface. Normally, readline is configured via a file which defines the behavior of the library; the details of the syntax for this can be found in the readline documentation available with your system or on the Internet. IPython doesn’t read this file (if it exists) directly, but it does support passing to readline valid options via a simple interface. In brief, you can customize readline by setting the following options in your configuration file (note that these options can not be specified at the command line):

readline_parse_and_bind: this holds a list of strings to be executed via a readline.parse_and_bind() command. The syntax for valid commands of this kind can be found by reading the documentation for the GNU readline library, as these commands are of the kind which readline accepts in its configuration file.

readline_remove_delims: a string of characters to be removed from the default word-delimiters list used by readline, so that completions may be performed on strings which contain them. Do not change the default value unless you know what you’re doing.

因此,您必须在配置文件中设置readline_parse_and_bind(默认情况下,这是在/path/to/ipython/dir/profile_default/ipython_config中)。您可以使用ipython profile create生成一个示例的默认配置。在

我发现的方法是用 vi键选项已启用。在

将keybinding模式设置为vi:

生成空白配置文件:

ipython profile create [profile-name]

运行该命令应显示生成的配置文件的路径, 它们是python(.py)文件。在

From: Source: Options Reference

Starting with 5.0, IPython uses prompt_toolkit in place of readline, it thus can recognize lines ending in ‘:’ and indent the next line, while also un-indenting automatically after ‘raise’ or ‘return’, and support real multi-line editing as well as syntactic coloration during edition.

This feature does not use the readline library anymore, so it will not honor your ~/.inputrc configuration (or whatever file your INPUTRC environment variable points to).

In particular if you want to change the input mode to vi, you will need to set the TerminalInteractiveShell.editing_mode configuration option of IPython. (emphasis mine)

因此,导航到ipython_config.py文件,并确保 其中包括以下几行:

^{pr2}$

使用特定的配置文件启动IPython:

Source: Manging Profiles

在终端上,键入以下命令(不要键入大括号 实际上,它们只是 配置文件)。在

$> ipython profile={profile-name}

相关问题 更多 >