Wallogit.com
2017 © Pedro Peláez
Control Vim using PHP
This is a hugely untested library for sending commands to a remote Vim instance. For an example of how to use it, look at example.php, (*1)
Make sure that your vim is compiled with +clientserver with vim --version | grep clientserver. If it starts with a + it supports it. If it starts with a - it doesn't. gvim and macvim tend to come with it enabled., (*2)
Start vim with vim --servername FOO to start it with the remote server enabled., (*3)
In your script, create a new client like so:, (*4)
$c = new Vimrunner\Client("FOO");
All of the available commands so far are in src/Vimrunner/Client.php., (*5)
The most common command will be writeLine., (*6)
// Will type "Hello World", with 0.1 seconds between each key press
// and add a new line "\n" at the end
$c->writeLine("Hello World", 1);
// You can also decide how you enter insert mode
// e.g. enter in append mode
$c->writeLine("Hello World", 1, "a");
writeLine will put you in normal mode once they're done typing., (*7)
Other useful methods:, (*8)
// Make sure we're in normal mode
$c->ensureInNormalMode();
// Send a string of key presses in normal mode
// e.g. Reformat the entire file
$c->normal("gg=G");
// Send a command
// e.g. :w
$c->command("w");
// Open a file for editing
$c->editFile("/tmp/example");