【问题标题】:Vim editor - zsh shell ipython magic %ed cannot find editorVim 编辑器 - zsh shell ipython magic %ed 找不到编辑器
【发布时间】:2016-03-05 03:59:00
【问题描述】:

我正在尝试使用 IPython 中的 %ed 魔法来使用 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

如何让它工作?

【问题讨论】:

    标签: vim ipython zsh oh-my-zsh


    【解决方案1】:

    尝试使用 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”文件。

    IPYTHONDIR根据man ipython

    IPYTHONDIR

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

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

    我还提到了版本,因为某些版本的设置似乎不同,对于 2.4.1,该设置被称为:

    c.TerminalInteractiveShell.editor = ...
    

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

    c.IPythonWidget.editor = ...
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多