Introduction to vimrunner-python

Note: I’d advise installing python libraries via virtualenv

I wanted to try out vimrunner-python but the only docs available are more API docs than usable documentation.

Here’s a 60 second guide to getting it running:

Make sure your install of vim supports clientserver:

[[ -n "`vim --version | grep client`" ]] && echo "Installed" || echo "Not installed"

If it doesn’t, read this post

Once it does, start an instance of vim in server mode:

vim --servername this_is_our_name

Create a python file with the following contents to talk to it:

import vimrunner

s = vimrunner.Server("this_is_our_name")
# initialize vim server
client = vimrunner.vimrunner.Client(s)

client.type("IHelloWorld<esc>");

Run the python file, see the words appear.

Useful functions

I used client.type() to send raw commands to the vim instance, but vimrunner-python provides a few useful abstractions.

  • client.insert(“Hello World”) – Will insert “Hello World” at the current location and leave you in insert mode
  • client.normal(“dd”) – Will send “dd” in normal mode, cutting the current line into a buffer

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply