Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tips for Setting Up Complex CTAGS Search Paths

Tags:

linux

vim

ctags

I want to be able to start up vim in an arbitrary subdirectory in my project and have it search up to the project root for the tags file, and then to search in an unrelated directory outside the project tree.

For example let's say I have the following:

~/projects/foo/bar/baz.c
~/projects/foo/tags
~/some/arbitrary/path/tags

I want to open baz.c from within the bar subdirectory, have it search up to find foo/tags and then to search some/arbitrary/path/tags if the symbol isn't found in foo/tags.

Now I know I can do:

set tags=./tags,tags;

to accomplish the first task. It's apparently the semicolon which tells vim to search up to the root. However neither of the following work:

set tags=./tags,tags,~/some/arbitrary/path/tags;
set tags=./tags,tags;~/some/arbitrary/path/tags

The first one finds only symbols from ~/some/arbitrary/path/tags while the second one only finds symbols in the tags file at the project root.

Anyone know how to do this? I'm on Linux buy the way.

like image 406
Robert S. Barnes Avatar asked Nov 17 '09 14:11

Robert S. Barnes


1 Answers

I use:

set tags=~/.tags
set tags+=~/.vim/tags/cpp
set tags+=~/src/git/gitsrc/tags
" and so on...

For generating tags in a particular project's root:

map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

I adapted this setup from the C++ code completion vim tip.

like image 166
Greg Bacon Avatar answered Oct 16 '22 22:10

Greg Bacon