Inn ~/script.vim, I have:
set runtimepath+=string(substitute(expand("%:p"), 'script\.vim', '', 'g'))
I have an alias in .bashrc:
alias vimscript="vim -S ~/script.vim"
Running string(substitute(expand("%:p"), 'script\.vim', '', 'g')) works as intended.
The problem is when using it in the set runtimepath expression, it doesn’t work when I call vimscript in terminal which calls script.vim. When I run set rtp in vim after being called by vimscript to check the runtimepath, the desired appended string isn’t showed (but the other ones are there).
I have some additions to @Laurence Gonsalves answer:
There is also «concat and assign» operator:
.=, socan be rewritten as
Code
will append
,'/some/path'to &runtimepath, while you probably need,/some/path.I guess that you want to append path to your script to runtimepath. If it is true, then your code should be written as
inside a script, or
from current editing session (assuming that you are editing your script in the current buffer).