How to run Vim in a Python interpreter?

Ruby has a gem called interactive_editor that allows you to enter a vim session when you enter vi in the Ruby interpreter.

Literally, we need interactive_editor.rb in the ~/.irbrc , for example:

 require '~/interactive_editor.rb' 

And we are done. When we do vi in an interactive session; vim starts up. As soon as we leave the editor, code is executed inside the vim session. Here is more detailed information on running vim in irb .

So, is there any equivalent in Python?

+4
source share
2 answers
 from os import system as sh def vim(fname): sh('vim ' + fname) 

Possible way (re) to load a module:

 import imp from os import system as sh def _vim(fname, globs): sh('vim ' + fname) (dirname, _, basename) = fname.rpartition('/') modname = basename.rpartition('.')[0] m = imp.load_source(modname, fname) globs[modname] = m 

and at any time when you import this into the interpreter, it is recommended to make the shell manually:

 def vim(fname): _vim(fname, globals()) 

because globals() , called in a python file, contains file globals, not an interpreter. I know this is not elegant. But I would recommend reloading the module manually, like reload(modname) , it gives you more control, although it can be tedious.

+2
source

The vim-ipython plugin is a two-way integration between IPython and Vim.

Quote from the readme file at https://github.com/ivanov/vim-ipython :

Using this plugin, you can send strings or entire files for IPython to execute, as well as return object introspection and word completion in Vim, like what you get: object?<enter> and object.<tab> in IPython.

Below is a demo of the plugin: http://pirsquared.org/vim-ipython/ .

+3
source

All Articles