Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
just as a hint (because :mksession is correct): – 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! – 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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .