Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto save vim session on quit and auto reload on start including split window state?

I like to split my vim screen in 3. one :vsplit and one :split. I want these windows and the files I worked on to be saved when I close vim. I also want these windows to automatically load when I start vim.

I tried to install gsessions (just added the file to the plugin folder), but nothing happend. I am new to vim so I don't know exactly how the configuration works.

like image 937
ganjan Avatar asked Feb 28 '11 12:02

ganjan


1 Answers

I modified 2ck's script slightly to save a .session.vim in your current working directory instead of the directory where your current open file is in.

Also, it checks if the file exists before sourcing it.

fu! SaveSess()     execute 'mksession! ' . getcwd() . '/.session.vim' endfunction  fu! RestoreSess() if filereadable(getcwd() . '/.session.vim')     execute 'so ' . getcwd() . '/.session.vim'     if bufexists(1)         for l in range(1, bufnr('$'))             if bufwinnr(l) == -1                 exec 'sbuffer ' . l             endif         endfor     endif endif endfunction  autocmd VimLeave * call SaveSess() autocmd VimEnter * nested call RestoreSess() 
like image 132
Wolph Avatar answered Oct 09 '22 10:10

Wolph