"Restore session" in gVim like in Firefox?

6

2

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?

Somebody still uses you MS-DOS

Posted 2010-06-04T13:07:33.190

Reputation: 4 143

Answers

3

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

UncleZeiv

Posted 2010-06-04T13:07:33.190

Reputation: 657

Do you mean associating :mksession each time I use :w for example? – Somebody still uses you MS-DOS – 2010-06-04T13:28:26.583

1

just as a hint (because :mksession is correct): http://www.vim.org/scripts/script.php?script_id=2010

– akira – 2010-06-04T19:35:46.320

yep that's what I meant – UncleZeiv – 2010-06-06T16:22:15.733

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! http://jaredforsyth.com/blog/2010/apr/9/vim-crash-recovery/

– Somebody still uses you MS-DOS – 2010-06-08T13:05:13.280

Enabling just that autocmd and adding -S to the gVim startup command will enable automatic session management! Thanks guys. – Merijn – 2011-05-12T06:15:41.937

3

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.

pan1nx

Posted 2010-06-04T13:07:33.190

Reputation: 131

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 – 2012-12-05T03:33:01.257