Vim编辑器 - zsh shell ipython magic%ed无法找到编辑器 [英] Vim editor - zsh shell ipython magic %ed cannot find editor

查看:205
本文介绍了Vim编辑器 - zsh shell ipython magic%ed无法找到编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the %ed magic in IPython to use vim as the editor.


  • vim已安装

  • ipython和ipython qtconsole都可以正常工作

  • zsh是最新的,用我的oh-my-zsh安装更新

我将我的偏好导出到zsh

I exported my prefernce to zsh

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

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

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

However, when I launch IPython and then invoke the %ed magic it fails

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

如何让它工作?

推荐答案

尝试使用IPython的配置文件配置作为指定编辑器的方法。为此:

Try using IPython's profile configuration as a means of specifying editor. To do this:

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

Firstly, generate default configuration files:

$ ipython profile create

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

Next, find your ~/.ipython/profile_default/..._config.py file to edit. For example on IPython 2.4.1,

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

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

Find the commented-out .editor setting, un-comment, and set it to vim. For example in IPython 2.4.1, this would look like

c.TerminalInteractiveShell.editor = 'vim'

您现在可以找到启动IPython的时间,%ed 它将调用vim:

You will now find when you start IPython, you can %ed and it will call up 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


FILES

FILES

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

IPython uses various configuration files stored in profiles within IPYTHONDIR. To generate the default configuration files and start configuring IPython, do 'ipython profile create', and edit '*_config.py' files located in IPYTHONDIR/profile_default.

$根据 man ipython


IPYTHONDIR

IPYTHONDIR

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

This is the location where IPython stores all its configuration files. The default is $HOME/.ipython if IPYTHONDIR is not defined.

您可以使用 ipython locate

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

Also I mention the version because settings seem different across some versions, for 2.4.1 the setting is called:

c.TerminalInteractiveShell.editor = ...

而在 IPython设置文本编辑器中给出的答案,此设置的名称不同:

Whereas in the answer given at IPython setting text editor, this setting was named differently:

c.IPythonWidget.editor = ...

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

Since it seems different between versions, after you generate the default configuration files, check and see how it is written in your IPython version, and act accordingly.

这篇关于Vim编辑器 - zsh shell ipython magic%ed无法找到编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆