I have autocmd BufEnter * silent! lcd %:p:h
in my .vimrc so that the current buffer's pwd is always set correctly. Unfortunately mksession
does not save sessions properly because of this.
Is there either a better way to save sessions, or a way to make these two features play together well? Disabling the autocmd temporarily with :noautocmd mksession session1
doesn't seem to work.
:set autochdir
will do the same as your autocmd, and is built-in. I'm using that one myself, and haven't encountered any problems with sessions. Of course, the directory that the session is saved to must be specified relative to the current file, though you could define a custom :Mksession
command that is always based on a fixed directory.