Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Vim's mksession to use relative paths?

I'm trying to save my session in Vim with relative paths to open files. With cur_dir in sessionoptions, the paths to files will be relative wrt. current directory, but the session file contains cd /path/to/base/directory command:

...
cd /path/to/base
badd +0 relpath1/file
badd +0 relpath2/file
...

If I leave curdir out of sessionoptions, the cd command disappears, but file paths will be absolute:

badd +0 /path/to/base/relpath1/file
badd +0 /path/to/base/relpath2/file

Is there a way to have only relative paths wrt. to whatever was the current directory when the session was created -- without plugins or writing scripts? So that the session file would only have:

badd +0 relpath1/file
badd +0 relpath2/file

My ultimate goal is to have a session file that I can copy around, e.g. from SVN checkout to another.

like image 908
huoneusto Avatar asked Nov 10 '12 14:11

huoneusto


1 Answers

You can't do that without setting up a wrapper function for it, AFAIK.

E.g. something like:

function! MakeSession()
  let b:sessiondir = getcwd()
  let b:filename = b:sessiondir . '/session.vim'
  exe "mksession! " . b:filename
  exe "edit! " . b:filename
  exe "g:^cd :d"
  exe "x" 
endfunction
like image 119
Zsolt Botykai Avatar answered Sep 25 '22 02:09

Zsolt Botykai