Python Interpreter Shell with Vi(m) integration possible?

好久不见. 提交于 2019-12-31 22:27:48

问题


I love to use bpython but in Ruby there is a gem called interactive_editor that makes it possible to combine Vi(m) with the Ruby shell which makes the Development process much more comfortable. A good introduction to interactive_editor: http://vimcasts.org/episodes/running-vim-within-irb/

Are there any tools (like interactive_editor for Ruby) available to combine the Python shell with Vi(m)?


回答1:


You could have a look at the vim-ipython vim plugin:

https://github.com/ivanov/vim-ipython

This requires you to install the ipython shell (but I recommend doing this anyway as it adds a lot of functionality to the standard python shell).

If you don't want to install ipython, I suggest having a look at the ConqueShell plugin for vim:

http://www.vim.org/scripts/script.php?script_id=2771

This lets you run shells within vim. Once you've sourced the vim-ball, all you need to do is

:ConqueTerm python

to get a python shell directly in vim.




回答2:


I couldn't get vim-ipython to work, so I made this .vimrc solution that works with ConqueShell:

imap <silent> <leader>m <Esc>Vy<C-w><C-w>p
nmap <silent> <leader>m Vy<C-w><C-w>p
vmap <silent> <leader>m y<C-w><C-w>p
imap <silent> <leader>n <Esc><C-w><S-w>']0j
nmap <silent> <leader>n <C-w><S-w>']0j

From a new Vim screen and ConqueShell installed, type :ConqueTermSplit python. Now return to the original window (the shortcut is <C-w><S-w>) and type in some Python code.

To send the line under to cursor to the interpreter, press <leader>m. I have the leader mapped to comma, so that's a pretty simple motion. To send a block of code, highlight some lines in visual mode and do <leader>m. It works the same way.

To return to your script, <leader>n goes to the line immediately following what you just executed. As a side benefit, you can also use this command to move from window to window quickly.

EDIT (2-20-2015): If you're using ipython as the interpreter, you need to run %autoindent to turn off auto-indenting to preserve formatting for some code blocks. Cheers!



来源:https://stackoverflow.com/questions/10278560/python-interpreter-shell-with-vim-integration-possible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!