Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I left some files opened in gVim, and hibernated my machine.

Unfortunately, there was some error, and I lost my gVim session.

Is it possible to do like modern browsers nowadays (like Firefox), that after "crashing" (not exiting in normal ways), showing a "Restore last session" dialog in my gVim?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

One possibility would be to run :mksession periodically. Vim does not support timers as far as I know, but you could associate :mksession to a :autocmd event such as BufNewFile.

A possible event to use in these cases is VimLeavePre, e.g.:

autocmd VimLeavePre * mksession! .vim.sess
share|improve this answer
    
Do you mean associating :mksession each time I use :w for example? –  Somebody still uses you MS-DOS Jun 4 '10 at 13:28
1  
just as a hint (because :mksession is correct): vim.org/scripts/script.php?script_id=2010 –  akira Jun 4 '10 at 19:35
    
yep that's what I meant –  UncleZeiv Jun 6 '10 at 16:22
    
I did a different solution, but using a similar concept that you suggested: autocmd VimLeavePre * mksession! .vim.sess I think it would be a good idea to you to edit your answer and add the VimLeavePre approach! jaredforsyth.com/blog/2010/apr/9/vim-crash-recovery –  Somebody still uses you MS-DOS Jun 8 '10 at 13:05
    
Enabling just that autocmd and adding -S to the gVim startup command will enable automatic session management! Thanks guys. –  Merijn May 12 '11 at 6:15
add comment

If you want another hint, or something that is more user friendly and asks you at start up if you want to load the session, you could give a try to http://www.vim.org/scripts/script.php?script_id=3150 . I use it and it works quite well for me. You can have multiple sessions and it is very user friendly. You can SaveSession, OpenSession, DeleteSession and the files are stored in .vim/sessions so that you can use still mksession if you want.

share|improve this answer
    
I'm with too many plugins already, I started using builtin functions for some stuff... but thanks for the suggestion! –  Somebody still uses you MS-DOS Dec 5 '12 at 3:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.