Making gvim 'instance-only'

I want to make gvim be 'instance-only', i.e., know of an option or something that opens the file as a tab on my already-open gvim instance instead of opening a new one.

Allow me to just clarify something here ... in vim, tabs are not what people would expect them to be. In most programs they are an "instance" of a file (one tab/one file), but in vim they are merely a "viewpoint" into which you can have several vim windows, each one holding whatever you put in it.

Vim, when opening a file, opens it in a buffer. One buffer for every file. You can view the list of opened buffers with

:ls

Example to clarify: suppose I have a gvim window open with one file, module1.c. Supposing I'm on a terminal, what command do I have to enter in order to make 'module2.c' open in the same window that now has module1.c?

Again, we have a terminology problem. For the sake of discussion, I'll assume you mean "window" as in a windows window, and not a vim internal window. If you wish to open a file in an already opened gvim instance try

gvim first_file.dat
gvim --remote-tab second_file.dat

This can easily be shortened by putting it in a .bat file (if you're on windows), and then you don't have to type the "--..." part over and over again.

PS: I'm aware that there's a -p option that allows me to open multiple files in multiple tabs. But what I'm looking for is a way to open a new tab from OUTSIDE gvim AFTER it is running already.

Interesting, I didn't know about that one :)

How to do it? Is it even possible?

Tell if that is what you were looking for.


Vim can do this when run in clientserver mode, if it was compiled with the +clientserver option.

Launch the first vim instance with the --servername option:

gvim --servername FILES --remote-silent file.txt

Now, you can open further files in this instance by either providing --servername, or with just the --remote option.

gvim --remote file2.txt

gvim --servername FOOBAR --remote file3.txt

Taken from the vim manual documentation on the clientserver mode. Afaik, the new files are opened as buffers on the active tab. I'm not sure if vim can be configured to open the incoming files in new tabs.