Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
Yeah, that is exactly what I was looking for! =D Also, you can shorten the command with a shell script put on the /usr/bin folder (I called mine 'gvimt') –  Rafael Almeida Dec 25 '09 at 3:42
    
excellent, thank you. I did alias=vim='/c/Program\ Files\ (x86)/Vim/vim73/gvim.exe --remote-tab' in cygwin –  Jay R. Wren Apr 29 '11 at 19:57
    
You can do "Function g{ param($file) gvim --remote-silent $file }" in Powershell –  Zotov Feb 4 '12 at 15:25
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.