Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save and Restore vim state

Tags:

vim

How I can save the state of the vim after exit and then restore this state when I open it?

So it seems like it did not close vim.

like image 932
itun Avatar asked Feb 08 '12 08:02

itun


People also ask

How do I save a Vim session?

To Save a Session ( :mksession , :mks )vim file on the directory where the current Vim execution was started. Using exclamation mark, :mks! the command overwrites Session. vim file if it exists in the directory. You can specify a custom file name to save the session :mks!

How do I save a workspace in Vim?

You can save the current session (or buffer layout) by giving the command :Obsession . If you don't supply an argument, it writes a session file called Session. vim by default. To reload a session, either use vim -S <session-name> or :source <session-name> if you're inside Vim already.

How do we save and quit for all active tabs Vim?

:wa - save all tabs / unsaved buffers. :xa / :wqa - save all tabs / unsaved buffers and exit Vim.


1 Answers

Use vim sessions, it's an awesome feature! (Adding basic usage here--Kent's answer points to these details.)

To save the current views+settings for your current editing session do:

:mksession path/to/my-session-file.vim

To open/restore the session do:

% vim -S path/to/my-session-file.vim

To overwrite previously saved session with the current one just add a !:

:mksession! path/to/my-session-file.vim
like image 196
jimmont Avatar answered Nov 16 '22 02:11

jimmont