Mvim open file as new tab in existing window from the command line

vim

I frequently use the command:

mvim -p file1 file2

to open multiple files in one window as tabs.
However it often happens that I subsequently want to open another file from the command line.
How do I tell mvim to open it as a new tab in the existing open window?

Best Answer

$ mvim --remote-tab file3

MacVim first window is a Vim instance with --servername set to VIM. Each subsequent instance is named VIM1, VIM2 and so on. The command above opens a new tab in the first instance by default, it's the equivalent of:

$ mvim --servername VIM --remote-tab .profile

If you want to open a tab in a specific instance, check its name at the top of the window. Assuming it's VIM1, do:

$ mvim --servername VIM1 --remote-tab .profile
Related Question