How to specify where to generate the tags file
Asked Answered
H

3

8

I currently have a project directory like this

MainProject
|_ProjectA
|   |_src
|      |_file1.cpp
|      |_file2.cpp
|      |_.....
|      |_tags <---tag file generated here  
|_ProjectB
|   |_src
|      |_file3.cpp
|      |_file4.cpp
|      |_.....
       |_tags <---tag file generated here

Now file4.cpp uses items in file1.cpp however it seems that since its in a different folder I get the message

cstag - tag not found

Currently i went into my ProjectA and ProjectB and did this for each

ctage -R .

as a result of which tags file got generated in each project. My question is how can I specify where to generate the tags file. In that case all the tags file will be next to each other and hopefully that will solve this problem

Hydrops answered 23/7, 2017 at 8:59 Comment(0)
S
4

The simplest solution would be to generate a single tags file:

$ cd MainProject
$ ctags -R .

and tell Vim to recurse upward when looking for tags files:

set tags=./tags;,tags;
Seducer answered 23/7, 2017 at 10:43 Comment(0)
N
3

I recommend using the gutentags vim plugin to handle your tag file generation. Gutentags is locating your project root directory by looking for SCM folders (e.g. .git) and generates the tags file for the whole project.

There is no other configuration needed but you can specifiy another cache dir if you like (g:gutentags_cache_dir). Take a look in to the help file for further configuration options help gutentags.

Nominalism answered 23/7, 2017 at 10:9 Comment(0)
H
1

There doesn't exist only one way to answer your need. The answers may also depend on other specifics, or on what you're ready to do.

For instance, if all your projects were independently managed in VCS (IOW, if they have a .git/ or a .svn/ at their root) you would have access to automagic solutions. gutentags is one of them -- see @apparat's answer. There also exist solutions independent of vim that listens for committed files or for modified files -- @romainl has just presented a few of them on reddit yesterday, and I'm quite confident they have already been described on SO. There is also my lh-tags plugin, that's quite similar to gutentags, and that automatically sets the &tags for each buffer belonging to a project -- I've haven't check what gutentags does on this topic.

If your projects aren't under a VCS, you'll need another way to say: "this is project foo", and "this is project bar". This SO Q/A addresses this topic. From there you should be able to set (locally) l:&tags to whatever is best for each project, and even to tune how vim plugins that generates tags shall operate -- I'm quite a (the?) monomaniac regarding project awareness in my plugins. NB: in lh-tags case, you just need to tell the plugin where the tags files shall be generated, it'll update &tags accordingly.

Hohenstaufen answered 23/7, 2017 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.