vim: save a list of open files and later open all files

Maybe the bug/conflict with :mksession is only if you have parts of :mksession enabled that you don't care about.

Try this:

:set sessionoptions=buffers
:mksession

Another answer suggests session manager plugins, which are great. But I have a very lightweight alternative that I'll leave here for posterity. (Since it has been quite a while since this question was active.)

The code below automatically saves the current session on shutdown, and sets a key command to reload it manually (handy for when I really do want a new session with new files). If you really do want to unconditionally restore the previous session whenever vim is started up again, uncomment the 'VimEnter' line.

As a bonus, this also enables manually saving and restoring a separate session at will with a keypress.

Somewhere in ~/.vim/vimrc

" Automatically save the current session whenever vim is closed
autocmd VimLeave * mksession! ~/.vim/shutdown_session.vim

" <F7> restores that 'shutdown session'
noremap <F7> :source ~/.vim/shutdown_session.vim<CR>

" If you really want to, this next line should restore the shutdown session 
" automatically, whenever you start vim.  (Commented out for now, in case 
" somebody just copy/pastes this whole block)
" 
" autocmd VimEnter source ~/.vim/shutdown_session.vim<CR>

" manually save a session with <F5>
noremap <F5> :mksession! ~/.vim/manual_session.vim<cr>

" recall the manually saved session with <F6>
noremap <F6> :source ~/.vim/manual_session.vim<cr>

The user can define for herself what is in a session with the 'sessionoptions' option, mentioned above: help sessionoptions


There are a couple plugins that take vim's session management a little bit further.

SessionMan and Autosess provide some commands and auto saving features that you might like.

Another one is the following: http://jaredforsyth.com/blog/2010/apr/9/vim-crash-recovery/

Very short, probably a vimrc kind of thing.

Tags:

Vim