Search code examples
vimctags

Include ctags files recursively from a directory


I am using Ctags with Vim successfully. Currently, my setting for tags is as below:

set tags=./tags;/

I have a directory ~/.ctags which contains files such as: ~/.ctags/rails, ~/.ctags/laravel etc. which are basically ctags generated for specific projects which I might need from some other project of mine.

Is there a way, I can tell Vim to include all these files for ctags-purposes? something like:

set tags+=~/.ctags/*

Can someone also explain to me the pros and cons of using this approach v/s generating all my ctags (from ruby, php, python, etc. projects) in a single file??

Regards,


Solution

  • :help 'tags' explains:

    The filename itself cannot contain wildcards, it is used as-is.

    So you either need to explicitly add all tags on startup:

    for tagfile in split(glob('~/.ctags/*'), "\n")
        let &tags .= ',' . tagfile
    endfor
    

    or change your tag generation to put identically named files in subdirectories. Then you can use the * wildcard to include them all:

    set tags+=~/.ctags/*/tags
    

    I haven't used tags that much, but I think it is a good practice to separate them. After all, Vim does support multiple tag file locations.