Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a string concatenation to the source command in vim?

Tags:

vim

My current .vimrc includes these two lines, which are a bit redundant

let g:opamshare = "/home/hugo/.opam/system/share"
source /home/hugo/.opam/system/share/vim/syntax/ocp-indent.vim

Is there a way to use the value of the opamshare variable in the source command on the second line? I tried

source g:opamshare . "/vim/syntax/ocp-indent.vim"

but that gives me a E172: Only one file name allowed error.

like image 679
hugomg Avatar asked Feb 11 '23 22:02

hugomg


1 Answers

From vim doc:

:so[urce] {file}        Read Ex commands from {file}.

You need to pass only one file as argument to source command.
It doesn't treat argument as string, so you cannot use .(dot) to concat strings.


Try this:

:exec printf('source %s/%s', g:opamshare, 'vim/syntax/ocp-indent.vim')
like image 111
kev Avatar answered May 20 '23 15:05

kev