10

is it possible to extend vim functionality via custom extension (preferably, written in Python)?

What I need ideally is custom command when in command mode. E.g.

ESC

:do_this

:do_that

3 Answers 3

20

vim supports scripting in python (and in perl as well, I think).

You just have to make sure that the vim distribution you are using has been compiled with python support.

If you are using a Linux system, you can download the source and then compile it with

./configure --enable-pythoninterp 
make
sudo make install

Inside vim, you can type

:version

to list the available features; if it has python support, you should see a '+python' somewhere (a '-python' otherwise).

Then, to check the usage of the python module, you can type

:help python

P.S: if you're going to compile the vim sources, make sure to check the available configure options, you might need to specify --with-python-config-dir as well.

P.P.S: to create a "custom command in command mode" (if I understand correctly what you mean), you can create a function "MyFunction" in a vim script (using python or the vim scripting language) and then invoke it with

:Call MyFunction()

Check

:help user-functions

for details

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

3 Comments

Hey orsogufo, I'm having trouble with this ... the "+python" doesn't show up even after compiling with the --enable-pythoninterp option. I set the python-config-dir to /usr/lib/python2.4/ I am using a standard Debian distro. Any suggestions? I'd be extremely grateful.
@shafik23: this is quite strange; are you sure the compilation was successful? did you receive any warning? The best suggestion I can give you is to read carefully the output of configure and make... and of course, if you find something strange you can ask a question! Cheers
@shafik23 I had a problem with symptoms like yours until I also installed the package python-dev. I followed the basic run of the instructions blog.deepinit.com/?p=6 i.e. edit Makefile in src/ to include CONF_OPT_PYTHON=’–-enable-pythoninterp’ line then 'make config' in src/ then make && make install from top level directory.
5

Yes it is. There are several extensions on http://www.vim.org/scripts/index.php

It can be done with python as well if the support for python is compiled in.

Article about it: http://www.techrepublic.com/article/extending-vim-with-python/

Google is our friend.

HTH

Comments

4

Had a problems to compile Vim with Python.

...checking if compile and link flags for Python are sane... no: PYTHON DISABLED" in the ./configure output.

On Ubuntu 10.04 you have to install python2.6-dev. The flags for ./configure are:

--enable-pythoninterp
--with-python-config-dir=/usr/lib/python2.6/config

Make sure you got a path to directory, which contains config.c file. Also no / at the end of the path! That caused me problems.

Comments

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.