Vim编辑器 - zsh shell ipython magic%ed无法找到编辑器

时间:2016-03-05 03:59:01

标签: vim ipython zsh oh-my-zsh

我正在尝试使用IPython中的%ed magic来使用vim作为编辑器。

  • 已安装vim
  • ipython和ipython qtconsole都可以正常工作
  • zsh是我用oh-my-zsh安装
  • 更新的最新版本

我将我的偏好导出到zsh

$ echo "export EDITOR=/usr/bin/vim" >> ~/.zshrc

$ echo "export VISUAL=/usr/bin/vim" >> ~/.zshrc

但是,当我启动IPython然后调用%ed魔术时它会失败

In [1]: %ed
IPython will make a temporary file named: /tmp/ipython_edit_pu4Yql.py
Editing.../bin/sh: 1: mvim: not found
WARNING: Could not open editor

如何让它发挥作用?

1 个答案:

答案 0 :(得分:3)

尝试使用IPython的配置文件配置作为指定编辑器的方法。要做到这一点:

首先,生成默认配置文件:

$ ipython profile create

接下来,找到要编辑的~/.ipython/profile_default/..._config.py文件。例如,在IPython 2.4.1上,

$ vim ~/.ipython/profile_default/ipython_config.py

找到已注释的.editor设置,取消评论,并将其设置为vim。例如在IPython 2.4.1中,这看起来像

c.TerminalInteractiveShell.editor = 'vim'

现在你会发现当你启动IPython时,你可以%ed它会调用vim:

$ ipython
Python 2.7.11+ (default, Feb 22 2016, 16:38:42)
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %ed
IPython will make a temporary file named: /tmp/ipython_edit_Tze8Ur/ipython_edit
_gghQG5.py
Editing... done. Executing edited code...
It works
Out[1]: 'print "It works"\n'

In [2]:

说明

man ipython

  

文件

     

IPython使用存储在配置文件中的各种配置文件   IPYTHONDIR。生成默认配置文件并启动   配置IPython,执行'ipython profile create',并编辑位于IPYTHONDIR / profile_default中的'* _config.py'文件。

根据{{​​1}}

IPYTHONDIR

  

IPYTHONDIR

     

这是IPython存储其所有配置文件的位置。如果未定义IPYTHONDIR,则默认为$ HOME / .ipython。

     

您可以使用man ipython查看IPYTHONDIR的计算值。

另外我提到了版本因为某些版本的设置看起来不同,因为2.4.1设置被称为:

ipython locate

IPython setting text editor给出的答案中,此设置的名称不同:

c.TerminalInteractiveShell.editor = ...

由于版本之间似乎不同,因此在生成默认配置文件后,请检查并查看它在IPython版本中的编写方式,并采取相应措施。

相关问题