4

I want to set an option to a string containing full path of current working directory. For example

set tags=getcwd()."\tags"    " retrieve the full path of the tags file in current working directory 

However, vim seems only accept expansion for let variables, it don't expand the function in set context.

Is there way to achieve expand things in set?

filbranden
  • 28,785
  • 3
  • 26
  • 71
Eric Sun
  • 153
  • 2

1 Answers1

11

You can use :let with Vim options as well, by prefixing the option name with a & sigil; cp. :help :let-option

let &tags = getcwd().'\tags'

Note that the literal string must be in single quotes (or the backslash doubled); else, the \t will expand to a tab character.


The other way would be by using :execute, but then you'd have to take care of escaping, so this is not recommended:

execute 'set tags='.escape(getcwd(), '\ ').'\tags'
Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61