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: .=
, so
let foo=foo.bar
can be rewritten as
let foo.=bar
Code
let &runtimepath.=','.string(path)
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
let &runtimepath.=','.escape(expand('<sfile>:p:h'), '\,')
inside a script, or
let &runtimepath.=','.escape(expand('%:p:h'), '\,')
from current editing session (assuming that you are editing your script in the current buffer).
The right hand site of a set
command is not an expression, it's a literal string.
You can manipulate options (the things set
sets) by using let
and prefixing the option name with an &
. eg:
let &runtimepath=substitute(expand("%:p"), 'script\.vim', '', 'g')
To append to runtimepath
with a let
you can do something like:
let &runtimepath=&runtimepath . ',' . substitute(expand("%:p"), 'script\.vim', '', 'g')
(The .
is the string concatenation operator.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With