Kolesnik's Personal Web Site

Using Vim as a server and client

The Vim editor has options --servername and --remote. I wanted to set it up in a way to have a single Vim editor running all the time (the Vim server), and open whatever file I want to edit inside the running Vim server instance (the Vim client).

I made an alias to start the Vim server.

alias vimserver='vim --servername vim'

The server name VIM is what the --remote option expects to find by default.

Now, I start xterm, execute vimserver inside it, and have the Vim instance running.

For the Vim client, I made the following script.

#!/bin/sh
vim --remote $*
xraise "- VIM"

From any xterm window I can type

vimclient file

and have the named file open for editing inside the existing Vim server.

I'm using the cwm window manager. xraise is a convinient way to bring the Vim server window in front. However, I don't know if that is required in other window managers or desktop environments.

xraise is a simple program I found on the StackOverflow.

xraise.c

To compile the program I used the following command

cc -I/usr/local/include -L/usr/local/lib -lX11 -o xraise xraise.c

then copied the generated binary to a directory under the PATH ($HOME/bin in my case).