我正在尝试在IPython中使用%ed魔术来将vim用作编辑器。
我将我的偏好导出到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
我该如何工作?
尝试使用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配置文件创建”,然后编辑IPYTHONDIR / profile_default中的“ * _config.py”文件。
IPYTHONDIR
根据man ipython
:
紫杉醇
这是IPython存储其所有配置文件的位置。如果未定义IPYTHONDIR,则默认值为$ HOME / .ipython。
您可以通过看到IPYTHONDIR的计算值
ipython locate
。
我还提到了该版本,因为设置在某些版本中似乎有所不同,对于2.4.1,该设置称为:
c.TerminalInteractiveShell.editor = ...
而在IPython设置文本编辑器给出的答案中,此设置的命名不同:
c.IPythonWidget.editor = ...
由于两个版本之间似乎有所不同,因此在生成默认配置文件后,请检查并查看它在IPython版本中的编写方式,并采取相应的措施。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句