Vi/Vim restore opened files

Tom picture Tom · Sep 13, 2009 · Viewed 21.3k times · Source

I was wondering if this common IDE feature is available.

Suppose I open many files using Vim, using vsplit and split. Then, I close everything.

The next day, I want to recover those files. That is, recover the way they were opened, not having to open each one (using split and vsplit) again.

Is that possible?

UPDATE:

Using mksession! and source commands, mapping commands in .vimrc file, is there a way to parameterize mappings so as to write a specific file?

for example:

map <F2> :mksession! ~/vim_session @INSERT_HERE<cr> "Save session to @INSERTHERE file

Thanks in advance

Answer

hgmnz picture hgmnz · Sep 13, 2009

You can map using :mksession and :source to a set of keys for easy saving and restoring. Here's an example from my .vimrc that uses F2 and F3:

map <F2> :mksession! ~/vim_session <cr> " Quick write session with F2
map <F3> :source ~/vim_session <cr>     " And load session with F3