Question

I work on multiple projects, each ~3-5 million lines of code. I have a single tags file at the root of each project. I also have a tools directory shared between all of them.

disk1
 |
 +--Proj A
 |
 +--Proj B
 |
 +--Shared

disk2
 |
 +--Proj C
 |
 +--Proj D

When using tags, I would like Vim to first search the tags file at the root of my project, and then search the tags file for Proj X, and then search the tags file in Shared

I can't get Vim to find the tags file in Shared

in my .vimrc file I have:

set tags=tags;D:/Shared set tags=tags;,D:/Shared (thanks to romainl for catching a missing comma!)

but Vim only searches the local project tags file, not the shared one.

tags; should start at the CWD and traverse back up the tree until a tags file is found (finds the correct one at the project level).

D:/Shared is an explicit path and should find the tags file in that directory but fails to do so (I've checked, it does in fact exist).

I'm using Exuberand Ctags v5.8

Was it helpful?

Solution

set tags=tags;D:/Shared

means "look upward for a tags file from the current directory until you reach D:/Shared".

If you work in project C on disk 2 (let's call that disk E:), Vim will never visit D:/Shared because of two things:

  1. Upward search is not recursive.

    If no tags file is found at the root of the "current directory", Vim tries to find one at the root of its parent and so on until it reaches the topmost parent or the directory you specified after the semicolon. So, supposing you are editing E:\ProjectC\path\to\some\file, you can't expect Vim to find a tags file outside of that path. Vim will search for the following tags files, sequentially and, by the way, never find that hypothetic D:\Shared:

    E:\ProjectC\path\to\some\tags <-- KO
    E:\ProjectC\path\to\tags      <-- KO
    E:\ProjectC\path\tags         <-- KO
    E:\ProjectC\tags              <-- OK!
    E:\tags                       <-- KO
    

    It won't find any tags file not listed above.

  2. Windows doesn't have the equivalent of UNIX's "root" directory anyway.

    When you don't specify a stop directory, upward search climbs the inverted tree of your filesystem from the current directory (or an arbitrary start directory) to the root of the filesystem.

    Supposing you are still editing E:\ProjectC\path\to\some\file, upward search will ultimately look for the stop directory D:\Shared directly under every parent directory in the path to E:\ and will rather obviously never find it.

If you want Vim to find D:\Shared\tags wherever you are, you only need to add it explicitely to the tags option. Not as a stop directory but as a specific location:

set tags=tags;,D:/Shared/tags

Now, it says "look upward for a tags file from the current directory and use D:/Shared/tags".


Hmm… that was a lot of words just to explain the need for a single ,.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top