Is there an easy setting to make this switch?
Nope
I know I could write some vimscript to save my session marks somewhere and reload them to overwrite whatever viminfo is doing, but I don't want to spend the time if I don't have to.
That is exactly how you would do this.
Example code:
command! -bang -complete=file -nargs=? Mksession mksession<bang> <args> |
\ let [s:viminfofile, s:viminfo] = [&viminfofile, &viminfo] |
\ try |
\ let [&viminfofile, &viminfo] = [v:this_session . '.viminfo', 'f'] |
\ wviminfo! |
\ finally |
\ let [&viminfofile, &viminfo] = [s:viminfofile, s:viminfo] |
\ endtry
augroup ViminfoSessionRestore
autocmd!
autocmd SessionLoadPost * |
\ let [s:viminfofile, s:viminfo] = [&viminfofile, &viminfo] |
\ try |
\ let [&viminfofile, &viminfo] = [v:this_session . '.viminfo', 'f'] |
\ rviminfo! |
\ finally |
\ let [&viminfofile, &viminfo] = [s:viminfofile, s:viminfo] |
\ endtry
augroup END
NOTE: I have not tested this, so use at your own risk.
This provides :Mksession
which will write out a new viminfo
files named after the v:this_session
variable with a suffix of .viminfo
. This viminfo
file only contains file marks (f
option). After a session is loaded the SessionLoadPost
event is triggered. Attempt to read the session's viminfo
file via :rviminfo
on SessionLoadPost
event.
Other thoughts:
I would imagine creating another file in addition to the session file would become annoying. It might be better to append the file-mark data to the session file directly, but that would be more involved.
You may also want to look into some session plugins to make your session creation and management simpler, e.g. obsession.vim & VIM ProSession.
For more help see:
:h 'viminfo'
:h 'viminfofile'
:h this_session
:h SessionLoadPost
:h :mksession
:h :rviminfo
:h :wviminfo