Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim extension (via Python)?

Tags:

python

vim

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

like image 447
Pavel Bastov Avatar asked Sep 26 '08 10:09

Pavel Bastov


People also ask

Can I use Vim with python?

Vim is quite a powerful text editor which can add performance to the already fast typed language Python. Vim can be highly customizable and efficient to use as it has the power of adding custom plugins and plugins managers, key mappings, and the most critical weapon of vim - Access to the terminal straight away.

Is vim better than PyCharm?

"Smart auto-completion", "Intelligent code analysis" and "Powerful refactoring" are the key factors why developers consider PyCharm; whereas "Comes by default in most unix systems (remote editing)", "Fast" and "Highly configurable" are the primary reasons why Vim is favored.

How do I know if python supports Vim?

Run :ve[rsion] in command-line mode or run vim --version from Bash. If vim was compiled with Python 3, you'll find -python and +python3 . If vim was compiled with Python 2, you'll find +python and -python3 . If vim was compiled without Python support, you'll find -python and -python3 1.


1 Answers

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

like image 72
Paolo Tedesco Avatar answered Oct 20 '22 00:10

Paolo Tedesco