Peter's Blog

Redefining the Impossible

Python embedded in Vim


I have mentioned before about using VIM with embedded Python but I didn't mention what it is. Its a version of VIM specially compiled with built in python. Its a bit of a pain to set up as the main VIM site does not ship such a version and you have to build it yourself. This involves downloading the VIM source and the Python source and building VIM in such a way as to tell it where the python libraries can be found.

Once this is done it is quite cool. From within VIM I can type something like:

:py print dir("")

and remind myself of what methods a string object has. I can remind myself how to append arrays to arrays by typing

:py print [1, 2, 3] + [4, 5, 6]

and seeing how this compares to using append (it's different).

To manipulate the vim buffer it is possible to go:

:py import vim
:py vim.current.buffer[0] = 'hello peter'

to change the first line of the buffer to 'hello peter'

I think any other VIM/Python enthusiasts out there will already have their mouths watering by now and will be off downloading so I will just refer them to

:help py

VIM has similar support for perl and ruby and other sundry languages.


Filed under: python vim

Peter Says:

over 4 years ago

Essential lunch time reading.

Peter Says:

over 4 years ago

As someone who likes to spend their time reading techy stuff, thanks for the words of encouragement!

Peter

Peter Says:

over 4 years ago

But it is only me! Anyway installed Thompson DTI2300 Freeview. No BBC1! Removed some arial cables from the loft (I have a distribution amp and "multi-plex" VHF and UHF down the same downlead. Now I have BBC1 listed but no picture. Tonight I'll bypass the UHF/VHF wall socket in the hope of getting a picture. I believe that Dover requires the same C/D arial for DT as analogue so it should work. Assuming I'm pointed at Dover. Best go check the analogue channel numbers to see (or use a compass)! Zugz.

Comments are Closed