Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Control a vim instance through ruby code
tree: 4c8a1269f7

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Vimrunner Build Status

Using Vim's client/server functionality, this library exposes a way to spawn a Vim instance and control it programatically. Apart from being a fun party trick, this can be used to do integration testing on Vimscript.

This is still fairly experimental, so use with caution. Any issue reports or contributions are very welcome on the GitHub issue tracker.


Vimrunner can be used in one of two main ways:

# Vim will automatically be started and killed.
Vimrunner.start do |vim|
  vim.edit "file.txt"
  vim.insert "Hello"
# Vim will automatically be started but you must manually kill it when you are
# finished.
vim = Vimrunner.start
vim.edit "file.txt"
vim.insert "Hello"

Vimrunner will attempt to start up the most suitable version of Vim available, meaning one of the following:

  • vim if it supports headlessly creating servers (see Requirements below for more information);
  • mvim if you are on Mac OS X;
  • gvim.

If you wish to always start a GUI Vim (viz. skip using a headless vim) then you can use start_gvim like so:

Vimrunner.start_gvim do |vim|
  # ...

If you require an even more specific version of Vim, you can pass the path to it by instantiating your own Server instance like so:"/path/to/my/specific/vim").start do |vim|
  vim.edit "file.txt"

(You can also use the non-block form of start in both of the above examples.)

Calling start (or start_gvim) will return a Client instance with which you can control Vim. For a full list of methods you can invoke on the remote Vim instance, check out the Client documentation.


Vim needs to be compiled with +clientserver. This should be available with the normal, big and huge featuresets or by using MacVim on Mac OS X. In order to start a server without a GUI, you will also need +xterm-clipboard as described in the Vim manual.

The client/server functionality (regrettably) needs a running X server to function, even without a GUI. This means that if you're using it for automated tests on a remote server, you'll probably need to start it with Xvfb.

If you are using MacVim, note that you will need the mvim binary in your PATH in order to start and communicate with Vim servers.


The vimrunner executable opens up an irb session with $vim set to a running gvim (or mvim) client. You can use this for interactive experimentation. A few things you can try:

$vim.edit 'some_file_name'  # edit a file
$vim.insert 'Hello, World!' # enter insert mode and write some text
$vim.normal 'T,'            # go back to the nearest comma
$vim.type 'a<cr>'           # append a newline after the comma
$vim.write                  # write file to disk
Something went wrong with that request. Please try again.