Eric Weir | 29 Jun 2012 14:12

How did I get two instances of vim?


Or, more importantly, how do I get rid of the second?

I'm using the vim-session plugin. This morning I've been getting the following error message when I attempt to open a session:
session.vim 1.5: The 'default' session is locked by another Vim instance named 'VIM
1'! Use :OpenSession! to override. 

Didn't understand what it was telling me at first---because I *assumed* I did. Just realized this means I've got two sessions of vim running. Have no idea how I got two. Certainly didn't do it deliberately. 

How do I get rid of the second instance?

Thanks,
------------------------------------------------------------------------------------------
Eric Weir

“You will be needed in the movement when you realize 
that you are not needed in the movement.”

- Chris Crass

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Tim Gray | 29 Jun 2012 16:16
Favicon
Gravatar

Re: How did I get two instances of vim?

On Jun 29, 2012 at 08:12 AM -0400, Eric Weir wrote:
>Or, more importantly, how do I get rid of the second?

The second session might have already been closed.  Or crashed, or just 
improperly shut down.  Who knows without looking at your computer.  As 
long as you don't have any vim instances running in a terminal somewhere 
that you've forgotten about, or MacVim windows that you might have 
minimized and forgotten about, it's probably fine to ignore the warning.

You could use Activity Monitor to search for running or hung instances 
of vim if you are concerned, and (force) quit them from there.

>Didn't understand what it was telling me at first---because I *assumed* 
>I did. Just realized this means I've got two sessions of vim running. 

In my experience, starting up vim from scratch results in an instance 
called VIM.  Starting up a second one creates an instance called VIM1.  
In MacVim, these instance (server) names are in the title bar of the vim 
window.  Presumably your only MacVim window currently says 'VIM'.  If 
you open up more OS X windows, not vim panes, windows, or tabs, but 
windows in the OS, you start a new instance.  Do you have multiple 
windows that you opened with command-N or through the 'New Window' 
command in the File menu?  If so, you have multiple vim instances 
running.  Each OS X window in MacVim is it's own vim instance.

>How do I get rid of the second instance?

If it's still running somewhere in some window, just quit it.  If it's 
not running anywhere and the message is the result of improper session 
cleanup, remove ~/.vim/sessions/default.vim.lock.  Or just follow the 
instructions of what session told you to do:

> Use :OpenSession! to override.

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Eric Weir | 29 Jun 2012 17:08

Re: How did I get two instances of vim?


On Jun 29, 2012, at 10:16 AM, Tim Gray wrote:

> You could use Activity Monitor to search for running or hung instances of vim if you are concerned, and
(force) quit them from there.

Thanks, Tim. I found three. I forced all three to quit. When I started Vim back up and tried to load my session,
I got the same error message, only this time referencing an instance named vim2. Only one shows in Activity Monitor.

> In my experience, starting up vim from scratch results in an instance called VIM.  Starting up a second one
creates an instance called VIM1.  In MacVim, these instance (server) names are in the title bar of the vim
window.  Presumably your only MacVim window currently says 'VIM'.  If you open up more OS X windows, not vim
panes, windows, or tabs, but windows in the OS, you start a new instance.  Do you have multiple windows that
you opened with command-N or through the 'New Window' command in the File menu?  If so, you have multiple vim
instances running.  Each OS X window in MacVim is it's own vim instance.

I have on occasion opened a second OS X window of vim with command-N. Don't recall having done so recently.
[This problem just showed up this morning. Have never encountered it before.] I always quit vim with
command-q. If there's a warning about buffers being open, I write my files and then use command-q again. 

>> How do I get rid of the second instance?
> 
> If it's still running somewhere in some window, just quit it.  If it's not running anywhere and the message
is the result of improper session cleanup, remove ~/.vim/sessions/default.vim.lock.  Or just follow
the instructions of what session told you to do:
> 
>> Use :OpenSession! to override.

When I do this, I get a "swap file already exists" *every* time I load a file---no matter how many times I load
it. Even after I've written the file. I tried deleting "~/.vim/sessions/default.vim.lock." That at
least got the session to load when vim is started up, but I get the "swap file already exists" warning with it
too. Again, *every* time I open the file. Even after writing it.

I went to the folders for the documents in my session and deleted all the swap files. There were two instances
of each vimwiki swap file. Two taskpaper files had four instances. One had three. I deleted them all.

I went back to Activity Monitor. Found three new instances of vim. Quit them. Started vim. Default session
didn't load. Tried OpenSession. Got the warning about the session being locked by another instance of
vim---vim1 again. Deleted "~/.vim/sessions/default.vim.lock" again.

Finally, I think I have only one instance of vim. The default session loads when I start up vim. I don't get
repeated "swap file already exists" warnings. 

I quite vim and restart it. It opens as vim1 again! The default session doesn't load I look at the Activity
Monitor and there are two instances of vim again! What the hell is going on?

I'm wondering if the way I've been using vim-session is part of, or all of, the problem. Do I need to close the
session before quitting vim? I've been assuming that if the default session has the files I want on
startup, I wouldn't need to, that simply quitting vim, making sure all files are written before doing so,
would be OK.

Thanks for the suggestions of things to do. Haven't fixed the problem, but at least I have some things to work with.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA 
eeweir <at> bellsouth.net

"We do not inherit the earth from our ancestors, 
we borrow it from our children." 

- Chief Seattle.

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Eric Weir | 29 Jun 2012 17:18

Re: How did I get two instances of vim?


On Jun 29, 2012, at 11:08 AM, Eric Weir wrote:

> I'm wondering if the way I've been using vim-session is part of, or all of, the problem. Do I need to close the
session before quitting vim? I've been assuming that if the default session has the files I want on
startup, I wouldn't need to, that simply quitting vim, making sure all files are written before doing so,
would be OK.

My guess is this is the source of the problem. I cleaned everything out. Got rid of all the swap files. Got down
to one instance of vim. When I started it up, the default session loaded. I opened files and didn't get "swap
already exists." Saved the session, then closed the session. Restarted vim. Repeated the process.
Symptoms not recurring now.

Quitting vim without closing the session leaves ~/.vim/session/default.vim.lock in existence.
Closing the session before quitting vim gets rid of ~/.vim/session/default.vim.lock.

I had been quitting vim without closing the session since starting to use vim-session several days ago.
This is the first time I've encountered this problem.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eeweir <at> bellsouth.net

"Style is truth." 

- Ray Bradbury

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Tim Gray | 29 Jun 2012 17:38
Favicon
Gravatar

Re: How did I get two instances of vim?

On Jun 29, 2012 at 11:08 AM -0400, Eric Weir wrote:
>When I do this, I get a "swap file already exists" *every* time I load 
>a file---no matter how many times I load it. Even after I've written 
>the file. I tried deleting "~/.vim/sessions/default.vim.lock." That at 
>least got the session to load when vim is started up, but I get the 
>"swap file already exists" warning with it too. Again, *every* time I 
>open the file. Even after writing it.

Well, if you don't remove the swap file, then you should get that 
warning every time.  Note, this isn't a session.vim issue, this is just 
a vim issue.  You have swap files sitting around.  You get warnings when 
you try to open a file and there is a swap file for it already.  Vim 
makes swap files when you open a file.  It's supposed to remove them 
when you close a buffer.  If the buffer hasn't been closed properly (vim 
crashes, you lose power, or something else), then the swap file doesn't 
get deleted and you get warned the next time you open that file.  "Hey, 
there's a swap file here, do you want to edit it?"  Another common 
reason to get that warning is if you start editing a file that is 
already open by another instance of vim.

The question is why is why do you have swap files sitting around?

>I quite vim and restart it. It opens as vim1 again! The default session 
>doesn't load I look at the Activity Monitor and there are two instances 
>of vim again! What the hell is going on?

The processes in Activity Monitor are not necessarily all separate 
instances of Vim.  When I start up MacVim, I get one process named 
MacVim and two named Vim.  Opening up a new instance (VIM1), gives me 
one extra process named Vim in Activity Monitor.

I didn't bring up Activity Monitor as a way for you to count Vim 
instances.  It was a way to make sure that you could have nothing 
related to vim running.  Quit Vim.  Then check Activity Monitor for 
anything called vim in there.  If you've quit all instances of vim, 
there shouldn't be anything there related to vim.  Then you can start 
from a clean slate.

>I'm wondering if the way I've been using vim-session is part of, or all 
>of, the problem. Do I need to close the session before quitting vim? 

That would make sense to me.  I'm not sure if the lock file is cleaned 
up if you don't close the session.  I've not looked at the code to 
check.  I also don't particularly care because I just use :CloseSession 
when I'm done.

You seem to think all of your problems are always from whatever plugin 
you are running.  I would look into why a newly started MacVim instance 
is starting as VIM1 and not VIM.  I don't think that's a session thing.  
I also don't think it's a session thing that you have swap files 
scattered about.  That sounds like something related to improper shut 
down to me.

If you completely quit vim and restart it, you should have a vim server 
running with the name VIM (on MacVim at least).  If it's something else, 
like VIM1, something funny is going on - Vim must seem to think instance 
VIM is occupied.  This isn't a session thing (most likely).

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Eric Weir | 30 Jun 2012 12:39

Re: How did I get two instances of vim?


On Jun 29, 2012, at 11:38 AM, Tim Gray wrote:

> .... You have swap files sitting around.  You get warnings when you try to open a file and there is a swap file
for it already.  Vim makes swap files when you open a file.  It's supposed to remove them when you close a
buffer.  If the buffer hasn't been closed properly (vim crashes, you lose power, or something else), then
the swap file doesn't get deleted and you get warned the next time you open that file..... Another common
reason to get that warning is if you start editing a file that is already open by another instance of vim.
> 
> The question is why is why do you have swap files sitting around?

I haven't a clue. None of the suggestions above ring a bell. I don't think vim has ever crashed for me, I always
write my files before quitting vim, etc., etc. 

> The processes in Activity Monitor are not necessarily all separate instances of Vim.  When I start up
MacVim, I get one process named MacVim and two named Vim.  Opening up a new instance (VIM1), gives me one
extra process named Vim in Activity Monitor.
> 
> I didn't bring up Activity Monitor as a way for you to count Vim instances.  It was a way to make sure that you
could have nothing related to vim running.  Quit Vim.  Then check Activity Monitor for anything called vim
in there.  If you've quit all instances of vim, there shouldn't be anything there related to vim.  Then you
can start from a clean slate.

Don't know if I've ever seen a process called MacVim when I start MacVim. Yesterday and today, at least, they
been called Vim, Vim!, or Vim2. As I recall, in beginning to work with your suggestions yesterday, I
believe I had three processes called Vim running after I had quit vim. 

>> I'm wondering if the way I've been using vim-session is part of, or all of, the problem. Do I need to close
the session before quitting vim? 
> 
> That would make sense to me.  I'm not sure if the lock file is cleaned up if you don't close the session.  I've
not looked at the code to check.  I also don't particularly care because I just use :CloseSession when I'm done.

Yes, the lock file goes away when you close the session. Since starting to close the session prior to
quitting vim I've not had multiple instances of vim or persisting swap files.

> You seem to think all of your problems are always from whatever plugin you are running.  I would look into why
a newly started MacVim instance is starting as VIM1 and not VIM.  I don't think that's a session thing.  I also
don't think it's a session thing that you have swap files scattered about.  That sounds like something
related to improper shut down to me.

Again, I could be overlooking something, but none of your suggestions---improper shut down,
etc.---rings a bell. All I know is when I deleted all those swap files and started closing the session
before quitting vim, I haven't had the problem.

> If you completely quit vim and restart it, you should have a vim server running with the name VIM (on MacVim
at least).  If it's something else, like VIM1, something funny is going on - Vim must seem to think instance
VIM is occupied.  This isn't a session thing (most likely).

I'm puzzled how there could be instances of vim running that don't show up anywhere, at least in the places I
would expect them---in the menu bar, minimized on the desktop, in Activity Monitor.

Bottom line, the symptoms have been eliminated, though the problem, the underlying reason, has not been
solved. 

Even that much would not have been possible without your feedback. 

So thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eeweir <at> bellsouth.net

"Everywhere the crisis of the private financial system 
has been transformed into a tale of slovenly and overweening government 
that perpetuates and is perpetuated by a dependent and demanding population."

- Marilynne Robinson

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Eric Weir | 30 Jun 2012 12:45

Re: How did I get two instances of vim?


On Jun 30, 2012, at 6:39 AM, Eric Weir wrote:

> On Jun 29, 2012, at 11:38 AM, Tim Gray wrote:
> 
>> You seem to think all of your problems are always from whatever plugin you are running.  I would look into
why a newly started MacVim instance is starting as VIM1 and not VIM.  I don't think that's a session thing.  I
also don't think it's a session thing that you have swap files scattered about.  That sounds like something
related to improper shut down to me.
> 
> Again, I could be overlooking something, but none of your suggestions---improper shut down,
etc.---rings a bell. 

One thing I haven't mentioned: I start MacVim with QuickSilver. I type <ctrl> <space> to bring up qs, then mv
to get the MacVim icon displayed, then hit <return> to start vim. 

I don't know if that could get multiple surreptitious instances of vim going or not. 

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eeweir <at> bellsouth.net

"What is man without the beasts? If all the beasts were gone, 
men would die from a great loneliness of spirit." 

- Chief Seattle

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Tim Gray | 30 Jun 2012 15:53
Favicon
Gravatar

Re: How did I get two instances of vim?

On Jun 30, 2012 at 06:39 AM -0400, Eric Weir wrote:
>Again, I could be overlooking something, but none of your 
>suggestions---improper shut down, etc.---rings a bell. All I know is 
>when I deleted all those swap files and started closing the session 
>before quitting vim, I haven't had the problem.

You really shouldn't have to manually delete swap files if you are 
saving and closing your files properly.  Something is amiss.  You should 
ask the list directly about that.

>I'm puzzled how there could be instances of vim running that don't show 
>up anywhere, at least in the places I would expect them---in the menu 
>bar, minimized on the desktop, in Activity Monitor.

They aren't necessarily running.  I'm not sure how Vim records that it 
has instances up and running, but if it fails to record that an 
instances has CLOSED, then it might think the VIM instance is 
active (and it's not), so when you start up a new instance, you get 
VIM1.

To me, the signs point that your installation of Vim isn't doing proper 
housekeeping when you shut things down.  Maybe session.vim is involved, 
maybe not.  You could deactivate it and see the swap file behavior is 
different.  You could also keep an eye out on your instance names with 
it deactivated.  The only time you should see VIM1 is if you start up a 
second instance while one is already running.

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Eric Weir | 30 Jun 2012 19:18

Re: How did I get two instances of vim?


On Jun 30, 2012, at 9:53 AM, Tim Gray wrote:

> To me, the signs point that your installation of Vim isn't doing proper housekeeping when you shut things
down.  Maybe session.vim is involved, maybe not.  You could deactivate it and see the swap file behavior is
different.  You could also keep an eye out on your instance names with it deactivated.  The only time you
should see VIM1 is if you start up a second instance while one is already running.

I can produce the symptoms---multiple instances of vim, persisting swap files. I can do it reliably. Write
all my files. Then quit vim without closing the session that was loaded.

When I do that the vim process in Activity Monitor persists. The swap files for all the files included in the
session persist. The next time vim is started it starts as vim1. The default session will not be loaded
automatically. A second set of swap files will be created when I do OpenSession manually.

If I go through the same process with vim1 as I did with vim, the same thing happens. The two vim processes in
Activity Monitor persist. The swap files persist. The next time vim is started it starts as vim2. Etc.,
etc., etc.

If I close the session before quitting vim, the symptoms don't occur. If I don't, they do.

My conclusion: Quitting vim without closing the open session causes the problem.

Again, I could not have discovered this without your initial suggestions. So thank you again.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eeweir <at> bellsouth.net

"What is man without the beasts? If all the beasts were gone, 
men would die from a great loneliness of spirit." 

- Chief Seattle

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Gmane