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?

1 Answer 1


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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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