Tips for Setting Up Complex CTAGS Search Paths
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 tre开发者_如何学Goe.
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.
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.
replace the tilde with path to your home.
Your first "set tags" option works for me in Linux. (As in, I've done it before, and I just recreated it to be sure.) You can have many different paths in your tags option, both absolute and relative. However, in the second one, you have a semicolon in the middle of the list, which is incorrect. In fact, you don't need any semi-colon. I would also replace the ~ with the absolute path to your home, just in case, and remove the semicolons all together. Just have commas between each path.
Oh, and to search up a directory for the tags file, you need "../tags", not "./tags". A single dot means the current directory, two dots means the directory one up from where you are.
Is the tags file always in the project/ directory? If so, you don't need to "search up" to find the tags file. Just hard code the path to both files like this:
set tags=/home/you/projects/foo/tags;/home/you/some/arbitrary/path/tags
If not, you can try something like this:
set tags=/home/you/projects/**;/home/you/projects,/home/you/some/arbitrary/path/tags
I haven't tried this so you might have to experiment with it. There are some pre-conditions for it to work. See :help file-searching.
The single line syntax for set tags should be:
set tags=./tags,tags;,~/some/arbitrary/path/tags
The comma was missing after "tags;"
精彩评论