Making gvim ‘instance-only’

command linegvim

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.

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?

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.

How to do it? Is it even possible?

Best Answer

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.

Related Question