Python Vim Module - works

Tim Hammerquist tim at vegeta.ath.cx
Tue Nov 13 21:44:14 EST 2001


simonb at webone.com.au <simonb at webone.com.au> graced us by uttering:
[ snip ]
> If you can get it to compile (just edit the Makefile to make it point to 
> the right place...) try this with Vim 6.0:
>
> $ gvim --servername TEST
> $ python
>
> >>>import vim
> >>>vim.list()
> >>>
> ['TEST']
>
> >>>vim.send('TEST', 'iHello World!<ESC>')
> >>>
>
> You should see the string "Hello World!" neatly typed into the newly opened 
> vim window!!!
[ snip ]

Jonathan Gardner wrote:
> Well this sounds interesting...
> 
> i compiled vim60 with
> CONF_OPT_PYTHON = --enable-pythoninterp
> in the Makefile,
> but "import vim" fails.
> what next?
> 
> Simon Burton

It seems Simon didn't post the code to clpy, but only to vim-dev.
Searching the vim-dev archives, the code is indeed there It is a
python module (named vim.py) that may be loaded from outside of vim
(or rather gvim, at the moment).

The following worked perfectly on my box:

$ gvim
$ python
Python 2.1 (#2, Oct  8 2001, 20:43:58)
[GCC 2.95.3 19991030 (prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import vim, os
>>> vim.list()
['GVIM']
>>> vim.send('GVIM', '<ESC>:version<CR>')
>>> vim.send('GVIM', '<CR>')
>>> os.system('gvim')
0
>>> for i in vim.list():
...   vim.send(i, '<ESC>:version<CR>')
...   raw_input("Press <CR> to continue...");
...   vim.send(i, '<CR>')
...
Press <CR> to continue...
''
Press <CR> to continue...
''
>>> vim.list()
['GVIM', 'GVIM2']
>>> vim.send('GVIM2', ':q!<CR>')
>>> ^D

(can't close 'GVIM'...it's got my post!)

Congratulations, Simon!

Tim Hammerquist
-- 
If you had two people with a motive, and one of them
was alive, who would you arrest?
    -- Inspector Boot, "Theater of Blood"



More information about the Python-list mailing list