If you keep going back to the shell to find and open files, every
(g)vim command will open a new instance. You can tell vim to use an existing instance using its command server functionality.
Replace vim with gvim for all the commands if you use the graphical interface.
--servername command-line argument while starting vim. For example,
vim --servername CODING starts vim as a command server with name CODING. You can verify this by executing the command
vim --serverlist. Once you have started the server, use the command
vim --servername VIM --remote file1.txt in the shell to open in this command server instance. Go through
:help remote to look at all the options available.
I have made it more convenient for my setup by creating a wrapper script called
v, something like this:
#!/bin/sh if [ $# -eq 0 ] then vim --servername CODING else vim --servername CODING --remote-tab-silent $* fi
When I use the
v command, it invokes the command server mode. When I use it with file names, it uses the existing vim instance or creates a new one.
You can alias vim using
alias vim="vim --servername CODING --remote-tab-silent || vim --servername CODING". I prefer the script in this case so that I can use the vim command with other parameters like
--serverlist or our good old
-h. Also, it gives me to do some more personalizations, which is a topic for another post.
There is one catch here, vim has to be compiled with
+clientserver option. You can use the command
vim -h | grep servername to check if it is compiled in. If not, you can use the gvim, which as far as I know, supports this on all platforms.