20

Some applications have the notion of a "session", where you can run a command to load a file in an existing instance of an application.

For example, when I type:

$ firefox http://vi.stackexchange.com

Firefox re-uses an existing Firefox process, rather than creating a new one.

Is this possible with Vim?

22

You need vim compiled with +clientserver, and then you can use the command vim --servername SERVER to start a vim instance and vim --servername SERVER --remote FILE to open the file in the named vim instance.


macOS only

MacVim runs a server by default - you can use mvim --remote-tab-silent to open a file in a new tab in your existing MacVim instance, or mvim --remote-silent to open the file in a new buffer in the same tab.

4

While @craigp's answer is correct, I found it most convenient to simply add --remote-silent without worrying about server names,
(this assumes you don't want to address named vim instances).

This will start the server, or use one if its not already started.

It can be called like this:

gvim --remote-silent '+cal cursor(line,col)' some_file

eg:

gvim --remote-silent '+cal cursor(102,4)' src/code.c

I ended up needing to use a different method of moving the cursor because of this remote initialization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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