I have lots of files named by file.tags, ncl.tags, flod.tags, ... , fortran.tags. when opening file.tags, I want to set tags=file.tags.And when opening ncl.tags, I want to set tags=ncl.tags,and so on.

I put the following in my .vimrc, it doesn't work.

let g:current_file=expand("%:t")
au Bufread,BufNewfile tags set filetype=tags tags=g:current_file

1 Answer 1


The g:current_file is evaluated in your ~/.vimrc at startup, i.e. before any file has been loaded. You need to do the evaluation inside the :autocmd; either with :execute, but for options, it's more elegant to use :let &optionname = ... instead:

au Bufread,BufNewfile *tags setlocal filetype=tags | let &tags = expand("%:t")

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.