Single Instance vim

If you keep going back to the shell to find and open files, every (g)vim command will open a new instance. You can tell vim to use an existing instance using its command server functionality.

Replace vim with gvim for all the commands if you use the graphical interface.

Use --servername command-line argument while starting vim. For example, vim --servername CODING starts vim as a command server with name CODING. You can verify this by executing the command vim --serverlist. Once you have started the server, use the command vim --servername VIM --remote file1.txt in the shell to open in this command server instance. Go through :help remote to look at all the options available.

I have made it more convenient for my setup by creating a wrapper script called v, something like this:


if [ $# -eq 0 ]
    vim --servername CODING
    vim --servername CODING --remote-tab-silent $*

When I use the v command, it invokes the command server mode. When I use it with file names, it uses the existing vim instance or creates a new one.

You can alias vim using alias vim="vim --servername CODING --remote-tab-silent || vim --servername CODING". I prefer the script in this case so that I can use the vim command with other parameters like --serverlist or our good old -h. Also, it gives me to do some more personalizations, which is a topic for another post.

There is one catch here, vim has to be compiled with +clientserver option. You can use the command vim -h | grep servername to check if it is compiled in. If not, you can use the gvim, which as far as I know, supports this on all platforms.

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.



Abhijit Nadgouda
iface Consulting
+91 9819820312
My bookmarks


This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.