6

I think this is not quite a duplicate, although it's close.

I often work with multiple, slightly different, checkouts of the same multi-directory project. I'd like to be able to jump around using tags and gf, always staying within the current checkout, without having to type anything at startup.

There is a different tags file at the top-level directory of each checkout. The checkouts are numerous and their locations far from static, so hard-coding in paths is not an acceptable solution.

A simple

set tags=tags;/

seems to work acceptably for the tags part. But to get gf to work I need to append the location of the tags files thus found (notably including the top-level directory) to the path somehow. Any ideas on how to do this?

  • 1
    Even though the location is not static, for a given checkout they are fixed to a specific location? I'm wondering if you couldn't setup a sort of "Per Project vimrc" but instead set one up per checkout. – jecxjo Apr 16 '15 at 19:11
  • 2
    See vi.stackexchange.com/questions/2944/… - fugitive.vim + .git/tags = different tags per project – Collin Grady Apr 16 '15 at 22:35
  • @jecxjo This would work, but would be difficult for me to set up since I work on a large multi-developer project controlled by mostly emacs users, who would not allow me to commit the .vimrc to the top-level directory. – AGML Apr 17 '15 at 21:29
8
let &path += fnamemodify(tagfiles()[0], ':p:h')

should add the path of your tags file's parent directory to the path option.

Updating path each time you enter a buffer is probably a good idea:

augroup UpdatePath
    autocmd!
    autocmd BufNewFile,BufRead,BufEnter * set path&vim | let &path += fnamemodify(tagfiles()[0], ':p:h')
augroup END
  • 1
    This looks good, but I get "E734: Wrong variable type for +=" when I include it. – AGML Apr 17 '15 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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