Petr Skocik
Petr Skocik

Reputation: 60056

Expanding vim variables in the set command

I'm trying to set path dynamically relative to a directory returned by a script:

I'm getting the variables correct, however, I'm stuck at making them expand at the point where I'm trying to prepend them to path.

Could you please assist? (Any comments as to how this might be done better are welcome -- I don't know vimscript very well).

function! FindRoot()
  let root=system('fs_findRoot |tr -d "\n"')
  if !empty(root)
    let src1=root.'/src1'
    let pr_r=root.'/pr/HEAD/r/nat'
    let pr_d=root.'/pr/HEAD/d/nat'
    echom src1 pr_r pr_d
    set path^=pr_r
    set path^=pr_d
    set path^=src1
  endif
endfunction

Upvotes: 1

Views: 514

Answers (1)

romainl
romainl

Reputation: 196476

You can't use an expression as value for any option using :set.

You need to use :let for that:

let &path = pr_r . "," . pr_d . "," . src1 . "," . &path

See :help :let-&.

Upvotes: 3

Related Questions