質問

I am using iPython. The docs says that I should be able to remap the readline library's keys using inputrc. Here is what I have in my inputrc:

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

These mappings simply do not work when I load iPython. I'm on OS X 10.9 Mavericks. I do not see any warnings that libedit is being used instead of readline. Any ideas?

役に立ちましたか?

解決

From the 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.

So, you have to set readline_parse_and_bind in the configuration file (by default, this is in /path/to/ipython/dir/profile_default/ipython_config. You can generate the default config with an example using ipython profile create.

他のヒント

The method I found was to create a new IPython profile with the vi-keys option enabled.

Set your keybinding mode to vi:

Generate blank config file:

ipython profile create [profile-name]

Running the command should show the path of the generated profiles, which are python (.py) files.

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)

So, navigate to the ipython_config.py file, and make sure the following lines are in it:

c = get_config()
c.TerminalInteractiveShell.editing_mode = 'vi'

Start IPython with a particular profile:

Source: Managing Profiles

At a terminal, type in the following command (don't type the braces literally, they're just a placeholder for the actual name of the profile).

$> ipython --profile={profile-name}

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top