Vim and Ctags: Ignoring certain files while generating tags

If you need to exclude more than just .html files:

You can't comma separate a list inside an exclude option. This doesn't work:

ctags --exclude=*.html,*.js ./*

However, you can pass multiple exclude options:

ctags --exclude=*.html --exclude=*.js ./*

Pass the -V option to help with debugging:

ctags -V --exclude=*.html --exclude=*.js ./*

Gives the output:

Reading initial options from command line
  Option: --exclude=*.html
    adding exclude pattern: *.html
  Option: --exclude=*.js
    adding exclude pattern: *.js

You can exclude a filetype using --exclude='*.html'


The simplest way in vim would be

 :!ctags {.,**}/*.{cpp,h}

Explanation: The braces expand to

:!ctags ./*.cpp **/*.cpp **/*.h **/*.h 

So it looks for source or header files in the current directory (./) or any nested directory (**/). Note **/ wouldn't match the current directory (it always matches at least 1 sub directory level)

In shell:

 find -iname '*.cpp' -o '*.h' -print0 | xargs -0 ctags

Explanation: This recursively finds all .cpp and .h files under the current directory and passes them to ctags on the command line.

The way print0 and -0 work together is to ensure it works correctly with weird filenames (e.g. containing whitespace or even new line characters)

I'll leave the rest of the ctags options for your own imagination :)

PS. For recent bash-es, you can use

 shopt -s globstar
 ctags {.,**}/*.{cpp,h}

and get much the same behaviour as in vim !


I didn't want to track down every filetype which might get processed in a large project, and I was only interested in Python, so I explicitly only processed python files using ctags --languages=Python .... The list of language names can be seen using ctags --list-languages.

Tags:

Vim

Ctags