Interactive Python programming in ... vi [was: Tab wars revisited]

G. S. Hayes sjdevnull at
Fri Jul 16 16:05:29 EDT 2004

Martin Christensen <knightsofspamalot-factotum at> wrote in message news:<87d62xoun1.fsf at>...
> Mark>   It sends the entire selected block to a new interpreter, yes.
> Mark> Not each line to a different interpreter, if that's what you're
> Mark> trying to say.
> I think what he was trying to say is this: for each time you send a
> code snippet to the interpreter, a new interpreter is started, and
> afterwards you won't have the same interpreter and its state to play
> with.
> With Emacs' Python mode, you can run a so-called inferior Python
> process, which is just to say that you have an interpreter running in
> Emacs. You can then keep sending code to this same interpreter.
> I should be greatly surprised if it weren't possible to do something
> similar in at least Vim.

The vimsh package allows you to run a shell under Vim; among other
things, you can run python under this shell.  I do this all the time,
with macros to run selected line(s) from my python code in the Python
window, maintaining state in between sending lines through Python--so
running "i=100", then going back to editing and later running "i=i+1",
"print i" will print 101.

This runs seperately from Vim's built-in Python interpreter, so you
don't have to worry about namespace collisions, etc (in fact, you can
easily have several vimsh python windows each running their own
interpreters, just like in emacs).

vimsh doesn't have smart terminal emulation (just dumb ptys), though,
so you can run line-oriented programs fine this way, but you can't run
e.g. curses or advanced termcap programs in any useful way.  Not a big
deal for me.


More information about the Python-list mailing list