tags:

views:

56

answers:

1

I am editing a file like
/path/to/file.txt
with vim, hence the current directory is
/path/to.

Now, I have a directory
/other/path/to/vim/files
that contains sourceA.vim. Also, there is a sourceB.vim file in
/other/path/to/vim/files/lib/sourceB.vim

In sourceA.vim, I want to source sourceB.vim, so I put a
so lib/sourceB.vim
into it.

Now, in my file.txt, I do a
:so /other/path/to/vim/files/sourceA.vim
which fails, because the sourcing system is obviously not prepared for relative path names along with sourcing from another directory.

In order to fix this, I put a
execute "so " . expand("<sfile>:p:h") . "/lib/sourceB.vim"
into sourceA.vim which does what I want.

However, I find the solution a bit clumsy and was wondering if there is a more elegant solution to it.

I cannot put the sourceA.vim nor sourceB.vim into vim's plugin folder.

+2  A: 

Maybe you could modify your runtimepath in your vimrc or elsewhere:

set runtimepath+=/other/path/to/vim/files

Then use :runtime instead of :source in your sourceA.vim file:

runtime lib/sourceB.vim

You can then use the same ":so /../../../sourceA.vim" command as before...

dsummersl