I'd like to save my session before vim exits. Here's what I have so far:
function SaveSession()
let l:new_session = trim(inputdialog("Enter new session name: ", v:this_session, -1))
if l:new_session == -1
return
endif
execute "mksession! " . l:new_session
endfunction
autocmd ExitPre * call SaveSession()
This usually works, but if mksession
barfs vim exits without displaying the error and giving me a chance to react, causing me to lose my session.
According to :help ExitPre
, it sounds like it's possible to prevent it from exiting:
ExitPre When using `:quit`, `:wq` in a way it makes
Vim exit, or using `:qall`, just after
|QuitPre|. Can be used to close any
non-essential window. Exiting may still be
cancelled if there is a modified buffer that
isn't automatically saved, use |VimLeavePre|
for really exiting.
Is there an event I can raise or an exception I can throw? My only other idea is to create a new file with changes in it, but it feels hacky.