Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an option using a string in a vim script

Tags:

vim

I am trying to set an option but it does not work when using a variable.

This is what actually works:

set runtimepath+=~/.vim/bundle/foo/foo.vim/

When I try this, it DOES NOT work anymore:

g:foo_path = '~/.vim/bundle/foo/foo.vim/'
set runtimepath+=g:foo_path

I have seen a similar topic here and they use the following command to set an option with a variable:

let &backupdir=s:vimetc.'backups/'

However, when I try this:

 let &runtimepath+=g:foo_path

It still DOES NOT work. I am getting:

 E734: Wrong variable type for +=

Any ideas? Thanks.

like image 545
mbilyanov Avatar asked Sep 29 '13 15:09

mbilyanov


2 Answers

The problem is set does not support using string variables and let does not support += for string types.

This should work:

let g:foo_path = '~/.vim/bundle/foo/foo.vim/'
let &rtp.= ',' . g:foo_path
like image 81
cforbish Avatar answered Sep 18 '22 22:09

cforbish


another workaround

exe 'set runtimpath='.a:lines

after reviewer's comment, a 2.0 version

exe 'set runtimepath='.&runtimepath.','.g:foo_path
like image 22
Yan X Avatar answered Sep 21 '22 22:09

Yan X