What is the most elegant way to deal with sourced files that themselves source (relative) source fil

Posted by René Nyffenegger on Stack Overflow See other posts from Stack Overflow or by René Nyffenegger
Published on 2010-03-01T17:55:23Z Indexed on 2010/03/09 5:06 UTC
Read the original article Hit count: 173

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about vim

Related posts about gvim