Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vi/Vim restore opened files

Tags:

vim

vi

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

like image 707
Tom Avatar asked Sep 13 '09 01:09

Tom


People also ask

How do I reload files in vi?

You can use the :edit command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use :edit! to force the reload of the current file (you will lose your modifications). The command :edit can be abbreviated by :e . The force-edit can thus be done by :e!

How do I make a vi session resume?

You can use :sh to exit to your default shell then typing $ exit at the shell prompt will return you to Vim.


2 Answers

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 
like image 103
hgmnz Avatar answered Sep 22 '22 15:09

hgmnz


Give a look at the :mksession command, to create a session:

A Session keeps the Views for all windows, plus the global settings. You can save a Session and when you restore it later the window layout looks the same. You can use a Session to quickly switch between different projects, automatically loading the files you were last working on in that project.

like image 40
Christian C. Salvadó Avatar answered Sep 22 '22 15:09

Christian C. Salvadó