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

Lonnie Princehouse finite.automaton at gmail.com
Fri Jul 16 13:20:40 EDT 2004


> 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.
> 

If you use :!python, then of course you're starting a new python
session each time, because it's just running the interpreter via
system()...

BUT if you use :python, it will keep a persistent embedded interpreter
sitting around.  Try it:

:python foo=5
:python print foo

Reading the help file on :python is highly recommended!  The vim
module* is really spiffy.

*only works from inside the embedded interpreter, e.g. :python import
vim


Also-- I don't know of any code that does it, but it would be pretty
straight forward to (1) grab the vim cursor location  (2) parse the
buffer into an AST  (3) figure out where the cursor is inside the AST
and (4) do clever things like name completion, show function
arguments, and even interact with the debugger.



More information about the Python-list mailing list