Vim does have an escape function. It is called escape()
. (Take a look at :h escape()
). You can use this in combination with execute
(:h exec
) to set stl
properly.
vim $file -c "exec 'setl stl='.escape('${title}', ' ')"
The vim command for this specific example is
:echo escape('It is b.c', ' ')
It\ is\ b.c
So you can use execute to construct the string properly. Where .
is used for string concatenation.
:exec 'setl stl=' . escape('It is b.c', ' ')
Simpler solution from @NikitaKouevda is the following. (:h let-&
)
vim $file -c "let &l:stl = '${title}'"
And since vim can read environment variables itself you can simplify it further.
vim $file -c 'let &l:stl=$title'