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 workding 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?

up vote 8 down vote accepted

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'
  • Thank you, works perfectly – Eric Sun Nov 16 at 13:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.