Skip to content

Instantly share code, notes, and snippets.

@arizvisa
Created July 31, 2015 04:07
Show Gist options
  • Save arizvisa/1111910216788795cd4b to your computer and use it in GitHub Desktop.
Save arizvisa/1111910216788795cd4b to your computer and use it in GitHub Desktop.
auto-loading/saving a session to .vim.session
""" session auto-saving and things
"set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize
if has("unix") || &shellslash | let s:pathsep = '/' | else | let s:pathsep = '\' | endif
let g:session_file = join([getcwd(),".vim.session"], s:pathsep)
if (argc() == 0) && empty(v:this_session) && filereadable(g:session_file)
let g:session = 1
else
let g:session = 0
endif
function! Session_save(filename)
if g:session > 0
echomsg 'Saving current session to ' . a:filename
execute 'mksession! ' . a:filename
if !filewritable(a:filename)
echoerr 'Unable to save current session to ' . a:filename
endif
endif
endfunction
function! Session_load(filename)
if g:session > 0
echomsg 'Loading session from ' . a:filename
if filereadable(a:filename)
execute 'source ' . a:filename
endif
endif
endfunction
augroup session
autocmd!
autocmd VimEnter * call Session_load(g:session_file)
autocmd VimLeave * call Session_save(g:session_file)
augroup end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment