Vim and Ctags: Ignoring certain files while generating tags

浪子不回头ぞ 提交于 2019-12-03 10:45:23

问题


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


回答1:


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




回答2:


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



回答3:


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 !




回答4:


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.



来源:https://stackoverflow.com/questions/7736656/vim-and-ctags-ignoring-certain-files-while-generating-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!