Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to save and/or autosave a vim session?

Tags:

vim

You can create a session with

:mksession [sessionName.vim]

But if you later modify that session (ie. add/remove buffers) you have to manually save the session again, but doing so will generate the following error

E189: "Session.vim" exists (add ! to override)

which is an error you generally get with Save As not Save. So I have two questions:

  1. Is there no Save functionality here?
  2. Is there a way to autosave all changes to the session file?

Note: I am aware that I can issue mksession! sessionName.vim to overwrite an existing session file.

like image 292
puk Avatar asked Jan 10 '12 00:01

puk


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 vmware session?

You can save a session using the subroutine call syntax as follows: Vim::save_session():


1 Answers

  1. AFAIK mksession! is really the only way to go.
  2. You can do it very easily, with just one line in your vimrc:
    au VimLeavePre * if v:this_session != '' | exec "mks! " . v:this_session | endif

Of course there are plugins that help you save/load and automate saving sessions. Try searching http://vim.org for session.

like image 199
tungd Avatar answered Oct 13 '22 04:10

tungd