如何在*nix下的ipython中使用vi键?

时间:2022-02-06 07:16:12

Currently in Bash I use set -o vi to enable vi mode in my bash prompt.

目前在Bash中,我使用set -o vi在我的Bash提示符中启用vi模式。

How do I get this going in ipython?

如何在ipython中实现这一点?

Note: If an answer applies to all *nix, I'll remove the OS X from the title :)

注意:如果一个答案适用于所有*nix,我将从标题中删除OS X:)

5 个解决方案

#1


103  

In case someone's wandering in here recently, IPython 5.0 switched from readline to prompt_toolkit, so an updated answer to this question is to pass an option:

如果最近有人在这里闲逛,IPython 5.0从readline切换到prompt_toolkit,因此对这个问题的更新答案是传递一个选项:

$ ipython --TerminalInteractiveShell.editing_mode=vi

... or to set it globally in the profile configuration (~/.ipython/profile_default/ipython_config.py; create it with ipython profile create if you don't have it) with:

…或者在配置文件配置中全局设置(~/.ipython/profile_default/ipython_config.py;创建它与ipython概要创建如果你没有它)与:

c.TerminalInteractiveShell.editing_mode = 'vi'

#2


30  

Looks like a solution works for many other readline compatible apps:

看起来这个解决方案适用于许多与readline兼容的应用程序:

Set the following in your ~/.inputrc file:

在您的~/中设置以下内容。inputrc文件:

set editing-mode vi
set keymap vi
set convert-meta on

Source: http://www.jukie.net/bart/blog/20040326082602

来源:http://www.jukie.net/bart/blog/20040326082602

#3


11  

You can also interactively switch between Vi-mode and Emacs mode. According to the the readline docs to switch between them you are supposed to be able to use the M-C-j key combination but that only seems to allow me to switch to vi-mode - on my Mac (where ESC is used as the 'Meta' key) it is: ESC+CTRL+j. To switch back to Emacs mode one can use C-e but that didn't appear to work for me - I had to instead do M-C-e - on my Mac it is: ESC+CTRL+e.

您还可以在vi模式和Emacs模式之间进行交互切换。根据readline文档之间的切换,你应该能够使用M-C-j键组合,但这似乎只允许我切换到vi-mode——在我的Mac上(ESC被用作‘Meta’键),它是:ESC+CTRL+j。要切换回Emacs模式,你可以使用C-e,但这似乎对我不起作用——我不得不在我的Mac电脑上使用M-C-e,它是:ESC+CTRL+e。

FYI my ~/.inputrc is set up as follows:

通知你我的~ /。inputrc设置如下:

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on

#4


9  

ipython uses the readline library and this is configurable using the ~/.inputrc file. You can add

ipython使用readline库,这可以使用~/进行配置。inputrc文件。您可以添加

set editing-mode vi

to that file to make all readline based applications use vi style keybindings instead of Emacs.

要使所有基于readline的应用程序使用vi样式的键绑定,而不是使用Emacs。

#5


4  

I needed to be able to switch modes interactively in IPython 5 and I found you can do so by recreating the prompt manager on the fly:

我需要能够在IPython 5中交互地切换模式,我发现您可以通过动态重新创建提示管理器来实现:

a = get_ipython().configurables[0]; a.editing_mode='vi'; a.init_prompt_toolkit_cli()

#1


103  

In case someone's wandering in here recently, IPython 5.0 switched from readline to prompt_toolkit, so an updated answer to this question is to pass an option:

如果最近有人在这里闲逛,IPython 5.0从readline切换到prompt_toolkit,因此对这个问题的更新答案是传递一个选项:

$ ipython --TerminalInteractiveShell.editing_mode=vi

... or to set it globally in the profile configuration (~/.ipython/profile_default/ipython_config.py; create it with ipython profile create if you don't have it) with:

…或者在配置文件配置中全局设置(~/.ipython/profile_default/ipython_config.py;创建它与ipython概要创建如果你没有它)与:

c.TerminalInteractiveShell.editing_mode = 'vi'

#2


30  

Looks like a solution works for many other readline compatible apps:

看起来这个解决方案适用于许多与readline兼容的应用程序:

Set the following in your ~/.inputrc file:

在您的~/中设置以下内容。inputrc文件:

set editing-mode vi
set keymap vi
set convert-meta on

Source: http://www.jukie.net/bart/blog/20040326082602

来源:http://www.jukie.net/bart/blog/20040326082602

#3


11  

You can also interactively switch between Vi-mode and Emacs mode. According to the the readline docs to switch between them you are supposed to be able to use the M-C-j key combination but that only seems to allow me to switch to vi-mode - on my Mac (where ESC is used as the 'Meta' key) it is: ESC+CTRL+j. To switch back to Emacs mode one can use C-e but that didn't appear to work for me - I had to instead do M-C-e - on my Mac it is: ESC+CTRL+e.

您还可以在vi模式和Emacs模式之间进行交互切换。根据readline文档之间的切换,你应该能够使用M-C-j键组合,但这似乎只允许我切换到vi-mode——在我的Mac上(ESC被用作‘Meta’键),它是:ESC+CTRL+j。要切换回Emacs模式,你可以使用C-e,但这似乎对我不起作用——我不得不在我的Mac电脑上使用M-C-e,它是:ESC+CTRL+e。

FYI my ~/.inputrc is set up as follows:

通知你我的~ /。inputrc设置如下:

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on

#4


9  

ipython uses the readline library and this is configurable using the ~/.inputrc file. You can add

ipython使用readline库,这可以使用~/进行配置。inputrc文件。您可以添加

set editing-mode vi

to that file to make all readline based applications use vi style keybindings instead of Emacs.

要使所有基于readline的应用程序使用vi样式的键绑定,而不是使用Emacs。

#5


4  

I needed to be able to switch modes interactively in IPython 5 and I found you can do so by recreating the prompt manager on the fly:

我需要能够在IPython 5中交互地切换模式,我发现您可以通过动态重新创建提示管理器来实现:

a = get_ipython().configurables[0]; a.editing_mode='vi'; a.init_prompt_toolkit_cli()