If all you need to do is get the correct "tag" for the file, then this can be done easier:
set tags=./tags,tags;$HOME/programming,$HOME/programming/your/global/tags
The tags
parameter takes a comma (or space) list of entries. In my example, I have the following entries:
./tags
this means that it must first look for the tags
file in the current directorytags;$HOME/programming
this means searching for tags
file from the current directory to $HOME/programming
(for what a semicolon does, see file-searching ). If you do not specify a "stop" directory using a semicolon, then it looks up to the root directory /
$HOME/programming/your/global/tags
Finally, this is a tag file referenced by an absolute file name
My example is probably redundant for your purpose from your description, you only need this:
set tags=tags;$HOME/programming
But if you really need to change the working directory, you can add something like this (change lcd
to cd
if necessary) to your .vimrc:
au BufNewFile,BufRead *.js execute ":lcd " . fnamemodify(findfile("tags", ".;"), ":p:h")
source share