Vim scripting with python

T

Tool69

Hi,

I saw several old posts speaking of vim scripting in Python. This one
in particular :
http://www.velocityreviews.com/forums/t351303-re-pythonising-the-vim-eg-syntax-popups-gt-vimpst.html

But I didn't find where to put this "vimrc.py" on my Windows machine.
My "normal" _vimrc file is in C:\Documents and Settings\my_name .

Does anyone have any advice, and more genraly how to script Vim with
Python ?

I know I can put some python functions inside my vimrc file like
this :

function! My_function()
python << EOF
import vim, string
....blablabla
EOF
endfunction

but I would like to use external ".py" files.

Thanks.
 
S

Stuart D. Gathman

Does anyone have any advice, and more genraly how to script Vim with
Python ?

:py import sys
:py print sys.version
:help :py
I know I can put some python functions inside my vimrc file like
this :

function! My_function()
python << EOF
import vim, string
...blablabla
EOF
endfunction

but I would like to use external ".py" files.

:py import myfile

Use :py inside your vimrc - don't run python externally.
 
T

Tool69

Thanks Stuart,
I'll take a look at it.

Another thing :
Is there any way to made some modification de the python.syntax file
to highlight the functions call, i.e :
os.popen(...) ---> "popen(...)" will be highlighted.

Cheers.
 
J

J. Clifford Dyer

Stuart said:
:py import sys
:py print sys.version
:help :py


:py import myfile

Use :py inside your vimrc - don't run python externally.

Which versions of vim is this valid for? I tried ":py print 'Hello'",
and got "E319: Sorry, the command is not available in this version"

Cheers,
Cliff
 
N

Neil Cerutti

Which versions of vim is this valid for? I tried ":py print
'Hello'", and got "E319: Sorry, the command is not available in
this version"

The latest Windows build has the Python bindings included. The
one I have is version 7.0. Earlier Windows binaries didn't
generally have it.
 
B

Ben Finney

J. Clifford Dyer said:
Which versions of vim is this valid for? I tried ":py print 'Hello'",
and got "E319: Sorry, the command is not available in this version"

The ability of Vim to run Python commands is one of many optional
features that can be enabled or disabled when the program is
built. This allows a Vim program runtime of reasonable size (where
"reasonable" is decided by the person building the program); many of
the optional features are quite large, and building all of them into
the program would be a poor choice.

To find out what features are explicitly enabled or disabled in your
Vim program, type ':version'. The feature 'python' will be listed as
'+python' if enabled, '-python' if disabled.

If it's disabled and you want it enabled, you'll need to rebuild Vim
with that option enabled; or find someone who's done the same
(preferably the same person you got your default Vim from) and install
that program.
 
S

sjdevnull

J. Clifford Dyer said:
Which versions of vim is this valid for? I tried ":py print 'Hello'",
and got "E319: Sorry, the command is not available in this version"

It's valid for vim 5.0 and later (all official vim releases since
March 1998). You have to make sure python support is enabled at build
time with --enable-pythoninterp or other configure options that turn
it on (check for +python in the output of ":ver" to see if a
precompiled binary includes python support).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top