What is the most elegant way to work with source files that are source (relative) source files in VIM?

I am editing the file, for example, /path/to/file.txt
using vim, hence the current directory is this /path/to.

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

In sourceA.vim, I want to specify sourceB.vim, so I put the file so lib/sourceB.vim
in it.

Now, in the file.txt file, I do :so /other/path/to/vim/files/sourceA.vim
that which does not work, since the search system is clearly not prepared for relative path names along with a source from another directory.

To fix this, I put execute "so " . expand("<sfile>:p:h") . "/lib/sourceB.vim"
in sourceA.vim, which does what I want.

However, I find the solution a bit awkward and wondered if there is a more elegant solution for it.

I cannot put sourceA.vim or sourceB.vim in the vim folder plugin.

+3
source share
1 answer

Perhaps you can change your temporary path in your vimrc or elsewhere:

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

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

runtime lib/sourceB.vim

Then you can use the same command :: so /../../../ sourceA.vim as before ...

+5
source

Source: https://habr.com/ru/post/1734920/


All Articles