When saving a session with
sourceing it back, I noticed that alternate files (accessed via
C-^) are not persisted.
The docs don't mention anything about persisting alternate files. Is there a way/workaround/hack to do so?
Since there is no option to do this directly, you can hack around like this:
function! MkSession(filename) execute 'mksession! '.a:filename let l:alternate = fnameescape(expand('#')) if l:alternate != '' call system('echo "let @#=\"'.l:alternate.'\"" >> '.a:filename) endif endfunction command! -nargs=1 MkSession call MkSession(<f-args>)
This function will add the alternate file setting in the session, so when the session is loaded up, the alternate file is restored. (thanks to this answer)
You should be able to use it as is although I'm not sure it's 100% stable:
Instead of shoehorning fully-fledged session management into Vim with hacky Vimscript code, I eventually decided to use an external session management tool dedicated for this task.
I chose tmux (which also does a lot of other stuff that one would not necessarily care about) and am happy with it. Not only does it save the state of my Vim, but also the state of all my other console tabs/windows.