thanks,
-lev
IIUC, you want to make sure that Vim will restart with "the same windows
as when it last closed", right? For that purpose I would recommend the
following:
a) to have Vim save the session at shutdown:
autocmd VimLeave *
\ if exists('v:dying') && v:dying < 2 | mksession! | endif
I _think_ this will even run at interruptible crashes (e.g., after an
illegal opcode or a memory protect violation, but not if the operator
forces an uninterruptible hard crash). It may or may not run at an AC
power failure, depending on whether your computer can run a few seconds
after the AC fails, and on how long the OS will leave Vim for its
"emergency closedown".
The test for v:dying < 2 is to avoid doing it again if you get a second
crash after intercepting a first one (however, IIUC on non-Unix-like
OSes this variable is always either 0 or undefined, I'm not sure which)
-- see ":help v:dying".
b) to make it easier on you to save your session while working:
nnoremap <F12> :mks!<CR>
xnoremap <F12> :<C-U>mks!<CR>
snoremap <F12> <C-O>:<C-U>mks!<CR>
inoremap <F12> <C-O>:mks!<CR>
c) Educate yourself to type :qa or :xa or some variation on them
_before_ you close the OS, so that a "normal" system shutdown won't
cause a "crash" of Vim.
Note that (b) above is not strictly necessary on Linux if running gvim
with GTK2/Gnome2 GUI under KDE (KDE3, at least), where it will save its
session transparently at X11 closedown; but, strangely enough, the same
doesn't apply in a Gnome2 winmanager -- or at least that's what I'm
experiencing at the moment.
Best regards,
Tony.
--
The more things change, the more they stay insane.
On Dec 19, 2009, at 9:45 AM, Tony Mechelynck wrote:
> On 24/11/09 17:39, Lev Lvovsky wrote:
>>
>> I'd like to run an ':mksession!' on a regular basis (automatically) -
>> is there a generic timer function which I can wrap around that command
>> (running it ever hour for example)?
>>
>> thanks,
>> -lev
>
> IIUC, you want to make sure that Vim will restart with "the same windows as when it last closed", right? For that purpose I would recommend the following:
>
> a) to have Vim save the session at shutdown:
>
> autocmd VimLeave *
> \ if exists('v:dying') && v:dying < 2 | mksession! | endif
>
> I _think_ this will even run at interruptible crashes (e.g., after an illegal opcode or a memory protect violation, but not if the operator forces an uninterruptible hard crash). It may or may not run at an AC power failure, depending on whether your computer can run a few seconds after the AC fails, and on how long the OS will leave Vim for its "emergency closedown".
I suppose that the only danger with this is in case I have more than one instance of vim running from the same directory? Is there any way to check whether or not the instance of vim that I'm running is actually using the Session.vim file? I suppose it's possible that two instances can use the same session file, but that's less likely.
Thank you very much!
-lev
no prob.
>
> On Dec 19, 2009, at 9:45 AM, Tony Mechelynck wrote:
>
>> On 24/11/09 17:39, Lev Lvovsky wrote:
>>>
>>> I'd like to run an ':mksession!' on a regular basis (automatically) -
>>> is there a generic timer function which I can wrap around that command
>>> (running it ever hour for example)?
>>>
>>> thanks,
>>> -lev
>>
>> IIUC, you want to make sure that Vim will restart with "the same windows as when it last closed", right? For that purpose I would recommend the following:
>>
>> a) to have Vim save the session at shutdown:
>>
>> autocmd VimLeave *
>> \ if exists('v:dying')&& v:dying< 2 | mksession! | endif
>>
>> I _think_ this will even run at interruptible crashes (e.g., after an illegal opcode or a memory protect violation, but not if the operator forces an uninterruptible hard crash). It may or may not run at an AC power failure, depending on whether your computer can run a few seconds after the AC fails, and on how long the OS will leave Vim for its "emergency closedown".
>
> I suppose that the only danger with this is in case I have more than one instance of vim running from the same directory? Is there any way to check whether or not the instance of vim that I'm running is actually using the Session.vim file? I suppose it's possible that two instances can use the same session file, but that's less likely.
>
> Thank you very much!
> -lev
See ":help v:this_session" (which applies to sessions loaded by the -S
switch but not to the sessions saved transparently by the Gnome versions
of gvim).
Best regards,
Tony.
--
Diplomacy is the art of saying "nice doggy" until you can find a rock.