关于 IPython 的建议 MacVim 工作流程

发布于 2024-07-11 20:04:58 字数 1253 浏览 11 评论 0原文

我刚刚找到了 IPython 并且我可以报告说我深深地爱上了它。 感情是立竿见影的。 我认为这件事会变成持久的事情,就像 我的屏幕上的那个。 Ipython 和 screen 恰好也是最好的朋友,所以这是一部三角剧。 请注意,纯粹是柏拉图式的。

IPython 之所以让我心生好感,很大程度上是因为我通常喜欢命令提示符,尤其是受 *nix 启发、受 ksh、csh 启发的提示符(是的,chs 是一个怪物,但作为提示符,它有很多非常好的功能)功能)、bash 和 zsh。 对于 *nix 提示骑手来说,IPython 确实感觉像家一样。 混合系统 shell 和 python 也是一个非常好的主意。 另外,当然,IPython 在解决Python 挑战谜题时有很大帮助。 甚至是无价的。

现在,我也喜欢 Vim。 自从我以前学了 vi 以来,就没有回头路了。 当我有选择的时候,我就会使用 Mac。 现在我想将我的 IPython + MacVim 工作流程粘合在一起。 到目前为止我所做的是使用以下命令启动 Ipython:

ipython -e "open -a MacVim"

因此,当我从 IPython 进行编辑时,它会启动 MacVim 并加载文件/模块。 看起来有点像这样:

In [4]: %run foo #This also "imports" foo anew
hello world

In [5]: edit foo
Editing... done. Executing edited code... #This happens immediately
hello world

In [6]: %run foo
hello SO World

好的。 我认为这一点可以改进。 也许也有办法将 IPython 绑定到 MacVim 中? 请分享您的经验。 当然,如果您使用 TextMate 或其他一些最喜欢的编辑器,我也很感兴趣。 也许有些教训是通用的。

I've just found IPython and I can report that I'm in deep love. And the affection was immediate. I think this affair will turn into something lasting, like the one I have with screen. Ipython and screen happen to be the best of friends too so it's a triangular drama. Purely platonic, mind you.

The reason IPython hits the soft spots with me are very much because I generally like command prompts, and especially *nix-inspired prompts with inspiration from ksh, csh (yes, chs is a monster, but as a prompt it sport lots of really good features), bash and zsh. And IPython does sure feel like home for a *nix prompt rider. Mixing the system shell and python is also a really good idea. Plus, of course, IPython helps a lot when solving the Python Challenge riddles. Invaluable even.

Now, I love Vim too. Since I learnt vi back in the days there's no turning back. And I'm on Mac when I have a choice. Now I'd like to glue together my IPython + MacVim workflow. What I've done so far is that I start Ipython using:

ipython -e "open -a MacVim"

Thus when I edit from IPython it starts MacVim with the file/module loaded. Could look a bit like so:

In [4]: %run foo #This also "imports" foo anew
hello world

In [5]: edit foo
Editing... done. Executing edited code... #This happens immediately
hello world

In [6]: %run foo
hello SO World

OK. I think this can be improved. Maybe there's a way to tie IPython into MacVim too? Please share your experiences. Of course if you use TextMate or some other fav editor I'm interested too. Maybe some of the lessons are general.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

耳钉梦 2024-07-18 20:04:58

我使用 Linux,但我相信这个技巧也可以在 OS X 中使用。 我使用 GNU Screen 按照 此技巧。 我是这样做的:

首先,您应该打开一个终端并启动一个名为“ipython”或任何您想要的屏幕会话,然后启动 IPython:

$ screen -S ipython
$ ipython

然后您应该将其放入 .vimrc 中:

autocmd FileType python map F5 :w<CR>:!screen -x ipython -X stuff 

然后当您按 F5 时,它会告诉 Screen 在之前创建的 'ipython' 中执行命令 '%run file',其中 file 是 Vim 中当前的缓冲区。

您可以调整它以从 Vim 在 IPython 中执行您想要的命令。 例如我使用这个:

autocmd FileType python map <F5> :w<CR>:!screen -x ipython -X stuff 

这会执行%reset(对提示回答yes),然后更改为vim中当前缓冲区所在的目录,然后%run该文件。 如果您在 IPython 中激活了 %pdb,这会特别有用。

不要忘记您需要一个名为“ipython”的活动屏幕会话,并在其中运行 IPython。

如果你喜欢 Emacs。 IPython 良好的支持

\%run %:p:h\n'<CR><CR>

然后当您按 F5 时,它会告诉 Screen 在之前创建的 'ipython' 中执行命令 '%run file',其中 file 是 Vim 中当前的缓冲区。

您可以调整它以从 Vim 在 IPython 中执行您想要的命令。 例如我使用这个:


这会执行%reset(对提示回答yes),然后更改为vim中当前缓冲区所在的目录,然后%run该文件。 如果您在 IPython 中激活了 %pdb,这会特别有用。

不要忘记您需要一个名为“ipython”的活动屏幕会话,并在其中运行 IPython。

如果你喜欢 Emacs。 IPython 良好的支持

\%reset\ny\n\%cd %:p:h\n\%run %:t\n'<CR><CR>

这会执行%reset(对提示回答yes),然后更改为vim中当前缓冲区所在的目录,然后%run该文件。 如果您在 IPython 中激活了 %pdb,这会特别有用。

不要忘记您需要一个名为“ipython”的活动屏幕会话,并在其中运行 IPython。

如果你喜欢 Emacs。 IPython 良好的支持

\%run %:p:h\n'<CR><CR>

然后当您按 F5 时,它会告诉 Screen 在之前创建的 'ipython' 中执行命令 '%run file',其中 file 是 Vim 中当前的缓冲区。

您可以调整它以从 Vim 在 IPython 中执行您想要的命令。 例如我使用这个:

这会执行%reset(对提示回答yes),然后更改为vim中当前缓冲区所在的目录,然后%run该文件。 如果您在 IPython 中激活了 %pdb,这会特别有用。

不要忘记您需要一个名为“ipython”的活动屏幕会话,并在其中运行 IPython。

如果你喜欢 Emacs。 IPython 良好的支持

I use Linux, but I believe this tip can be used in OS X too. I use GNU Screen to send IPython commands from Vim as recommended by this tip. This is how I do it:

First, you should open a terminal and start a screen session called 'ipython' or whatever you want, and then start IPython:

$ screen -S ipython
$ ipython

Then you should put this in your .vimrc:

autocmd FileType python map F5 :w<CR>:!screen -x ipython -X stuff 

Then when you hit F5, it will tell Screen to execute the command '%run file' inside the 'ipython' created previously, where file is your current buffer in Vim.

You can tweak this to execute the command you want inside IPython from Vim. For example I use this:

autocmd FileType python map <F5> :w<CR>:!screen -x ipython -X stuff 

This executes %reset (answering yes to the prompt), then change to the directory where the current buffer in vim is located and then %run the file. This is specially useful if you have the %pdb active in IPython.

Don't forget that you need an active Screen session called 'ipython' with IPython running inside.

If you like Emacs. There is good support for IPython.

\%run %:p:h\n'<CR><CR>

Then when you hit F5, it will tell Screen to execute the command '%run file' inside the 'ipython' created previously, where file is your current buffer in Vim.

You can tweak this to execute the command you want inside IPython from Vim. For example I use this:


This executes %reset (answering yes to the prompt), then change to the directory where the current buffer in vim is located and then %run the file. This is specially useful if you have the %pdb active in IPython.

Don't forget that you need an active Screen session called 'ipython' with IPython running inside.

If you like Emacs. There is good support for IPython.

\%reset\ny\n\%cd %:p:h\n\%run %:t\n'<CR><CR>

This executes %reset (answering yes to the prompt), then change to the directory where the current buffer in vim is located and then %run the file. This is specially useful if you have the %pdb active in IPython.

Don't forget that you need an active Screen session called 'ipython' with IPython running inside.

If you like Emacs. There is good support for IPython.

\%run %:p:h\n'<CR><CR>

Then when you hit F5, it will tell Screen to execute the command '%run file' inside the 'ipython' created previously, where file is your current buffer in Vim.

You can tweak this to execute the command you want inside IPython from Vim. For example I use this:

This executes %reset (answering yes to the prompt), then change to the directory where the current buffer in vim is located and then %run the file. This is specially useful if you have the %pdb active in IPython.

Don't forget that you need an active Screen session called 'ipython' with IPython running inside.

If you like Emacs. There is good support for IPython.

雨夜星沙 2024-07-18 20:04:58

这个问题现在已经过时了,但仅供参考 - 如果您使用启用了 ZeroMQ 的 IPython 0.11,请查看 vim-ipython(0.11 附带的旧版本)。

使用此插件,您可以发送行或整个文件供 IPython 执行,还可以获取对象内省和单词完成
在 Vim 中,就像在 IPython 中使用: object?object. 得到的结果一样。

这篇文章上观看该插件的两个实际操作截屏视频。

This questions is stale now, but just for reference - if you're using IPython 0.11 with ZeroMQ enabled, take a look at vim-ipython (an older version of which shipped with 0.11).

Using this plugin, you can send lines or whole files for IPython to execute, and also get back object introspection and word completions
in Vim, like what you get with: object?<enter> and object.<tab> in IPython.

Take a look at two screencasts of this plugin in action on this post.

故事与诗 2024-07-18 20:04:58

在主目录中的 ipythonrc.ini 文件中,将编辑器更改为 MacVim。

In the ipythonrc.ini file in you home directory change the editor to MacVim.

心舞飞扬 2024-07-18 20:04:58

我也遇到过同样的问题。 经过实验,这是我的解决方案:如果您将 MacVim.app 放在 /Applications 中并且 mvim 在您的路径中,则在 ~/.ipython/ipythonrc 中将该行更改

editor 0

editor mvim --remote-tab-wait-silent

我认为您需要在后台保持 MacVim 打开。 您还可以使用 -f 标志。 从MacVim google 群组

I've had the same issue. After experimenting this is my solution: if you placed MacVim.app in /Applications and mvim is in your path, in ~/.ipython/ipythonrc change the line

editor 0

to

editor mvim --remote-tab-wait-silent

I think you need to keep MacVim open in the background. You could also use the -f flag. Look at this thread from the MacVim google group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文