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

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.

Answers


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...


Need Your Help

When sending Xcode project to someone, random compile errors? (Ver 4.4 to 4.3)

iphone objective-c xcode

So I made sure there are no references, and all my files (iPad app) are in the folder. I zip the folder and send it to someone. When they try to run, they get compiler errors regarding undefined me...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.