Skip to content

Instantly share code, notes, and snippets.

@mhinz
Last active December 26, 2015 09:59
Show Gist options
  • Select an option

  • Save mhinz/7133825 to your computer and use it in GitHub Desktop.

Select an option

Save mhinz/7133825 to your computer and use it in GitHub Desktop.
function! s:session_write(spath)
let ssop = &sessionoptions
try
set sessionoptions-=options
execute 'mksession!' a:spath
catch
execute 'echoerr' string(v:exception)
finally
let &sessionoptions = ssop
endtry
if exists('g:startify_session_savevars') || exists('g:startify_session_savecmds')
" put these commands into the session file
let cmds = get(g:, 'startify_session_savecmds', [])
" put these existing variables into the session file
let vars = map(filter(get(g:, 'startify_session_savevars', []), 'exists(v:val)'),
\ '"let ". v:val ." = ". strtrans(string(eval(v:val)))')
let sessionlines = readfile(a:spath)
call writefile(sessionlines[:-4] + vars + cmds + sessionlines[-3:], a:spath)
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment