excray
excray

Reputation: 2858

Vim and Ctags: Ignoring certain files while generating tags

I have a folder llvm2.9 in which i ran this command.

$> ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++

This was indexing methods in *.html files also which were present in llvm2.9/docs. I found this out because when i pressed ctrl-] for some class, it went to the html file.

How do i force ctags to use .cpp/.h files alone or ignore a particular directory.

Thanks

Upvotes: 30

Views: 18314

Answers (4)

skeept
skeept

Reputation: 12413

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

Upvotes: 29

Ben
Ben

Reputation: 8905

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.

Upvotes: 2

sehe
sehe

Reputation: 393064

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 !

Upvotes: 6

eupharis
eupharis

Reputation: 361

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

Upvotes: 18

Related Questions