4

In Ruby there is a gem called interactive_editor which allows entering a vim session when entering vi in Ruby interpreter.

Literally we need to require interactive_editor.rb in ~/.irbrc file, like this:

require '~/interactive_editor.rb'

And we are done. When we do vi in interactive session; vim is launched. As soon as we quit the editor, the code inside the vim session is executed. Here is more information about running vim within irb.

So, is there any equivalent to that in Python?

0

2 Answers 2

3

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

Quoting from the readme file on https://github.com/ivanov/vim-ipython:

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.

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

Sign up to request clarification or add additional context in comments.

2 Comments

Tab completion is not really I want, and I only want to use pure Python interpreter.
@SantoshKumar You can use Ipython shell with any python interpreter - ipython.org/…, it is simply more configurable than the standard python shell.
2
from os import system as sh
def vim(fname): sh('vim ' + fname)

A possible way of (re)loading the 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 anytime you import this into the interpreter, it is recommended to make a wrapper manually:

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

because globals() called in a python file holds the file's globals, not the interpreter's. I know, it's not elegant. But I'd recommend to reload module manually like reload(modname), it gives you more control, though may be tedious.

1 Comment

Code is not interpreted as soon as I exit vim. BTW its very near to what I want :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.