the home row

the home row | All posts tagged 'gvim'

Open a file into an existing instance of GVim

by Rob 16. January 2010 14:47

I use GVim a lot for editing most types of files. More than likely I'll launch files straight from a command line. One problem with this method is that each file appears in a new instance of GVim. This can quickly become difficult to manage. You can solve this problem by using the clientserver feature of GVim. Below is what the documentation says about clientserver functionality.

When compiled with the |+clientserver| option, Vim can act as a command server. It accepts messages from a client and executes them.

This means that your shell of choice can act as a client and fire commands to an existing instance of GVim. I use PowerShell ISE for simple file operations and launch all my programs from there. To launch a named server instance of GVim I run the following command:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername gvim

I keep GVim in my DropBoxso it moves with me to other computers. So you'll need to edit the path to the location of GVim on your computer. The servername argument is set to the name gvim, but you can set this to anything you like.

Now when you wish to open a new tab in this instance run the following command:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername GVIM --remote-tab .\main.ahk

In my case this launches the main AutoHotkey script into a new tab in the existing instance of GVim. You may be thinking this will mean more typing and ultimately take more time. To speed this whole process up I store a couple of snippets in an AutoHotkey script. This allows me to type "gvit" and expand this out to:

C:\Mydrop~1\Apps\gVimPortable\gVimPortable.exe --servername GVIM --remote-tab

I can then just add the file name to the end of the command to launch into my gvim instance. Not everyone's cup of tea, but I hope someone will find this useful. To find out more about snippets in AutoHotkey you can take a look at another of my blog posts.

 

del.icio.us Tags: ,

Tags: ,

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Rob Henry - .Net Developer and Keyboard Junkie

Page List