History Report a problem
Article Edit this page Discussion

Prevent a second instance of Vim from starting

From Vim Tips Wiki

(Redirected from VimTip957)
Jump to: navigation, search

Tip 957 Previous TipNext Tip

Created: July 7, 2005 Complexity: basic Author: Jonathan Orlev Minimum version: 5.7 Karma: 4/11 Imported from: Tip#957


For me, the most irritating thing when using the wonderful Vim is starting a second copy of Vim while a first one was already running.

For example: opening a file already open in the first Vim instance within a second instance of Vim gives an error message, because the swap file is already in use (not to mention that this might cause a loss of data).

So I added this to my vimrc. I am using gvim on Windows, but this will probably also work with gvim in other systems.

" If the v:servername ends with a number, then this is for sure a second
" copy of Vim.
if v:servername =~? '^.*[0-9][0-9]*$'
  echo "MyWarning: Another copy of gvim or Vim is probably loaded!"
endif

[edit] Comments

For users running gvim on Unixes, an alternative is to always use

/usr/local/bin/gvim --remote-silent FILENAME

If gvim is already running, the file is opened there. Otherwise, a new gvim instance is started.

For interactive shell sessions, it would help to define a shorter alias, such as:

alias gvimrem='/usr/local/bin/gvim --remote-silent'

Here is a better version for the tip. This is more general, and therefore preferable:

" If the serverlist contains more than one item, than another instance of
" Vim is loaded.
if serverlist() =~? "\n."
  echo "MyWarning: Another copy of gvim or Vim is probably loaded !"
endif

And you may also replace the operator '=~?' with '=~'


See the :RemoteOpen command from remoteopen.vim which is part of latex-suite plugin.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Astronomy Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Prevent a second instance of Vim from starting"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation