Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: reopen all previous files in a new session after restart

Tags:

vim

I usually have long lived vim session with dozens of files open. Once in a while, I need to restart vim, say to install a new plugin or apply some new config.

How can I reopen all the previous files after restart?

like image 247
Ying Xiong Avatar asked Jan 03 '23 04:01

Ying Xiong


1 Answers

You can use builtin sessions, perhaps with vim-session plugin.

A Vim session contains all the information about what you are editing.

This includes things such as the file list, window layout, global variables, options and other information. (Exactly what is remembered is controlled by the 'sessionoptions' option.)

The command

:mksession mysession.vim

saves the current session into the named file. Next time you start vim you can load the session:

vim -S mysession.vim

or inside vim

:source mysession.vim

You can automate saving sessions on VimLeave autocommand and reload a session on VimEnter but be careful abut restoring a session when vim is called, e.g., from git.

like image 152
phd Avatar answered Jan 14 '23 12:01

phd