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".

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.

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to