Short Articles

vim-gutentags ignoring exclude parameters from ctags

vim-gutentags vimrc config

This is another quick-and-dirty post added with the solely purpose of helping someone facing the same issue.

If you happen to be using vim-gutentags with vim, and are facing difficulties making it excluding certain paths from your tags file using the gutentags_ctags_exclude option in your vimrc, make sure that you are using the same file path format (relative vs. absolute) that vim-gutentags is expecting.

In order to know what file format it is expecting, add the followig line to your vimrc file:

let g:gutentags_trace = 1

This will output some debug information when you open vim, something like the following:

...
gutentags: Wildignore options file is up to date.
gutentags: Running: ['/home/jespinal/.vim/plugged/vim-gutentags/plat/unix/update_tags.sh', '-e', '/home/jespinal/bin/ctags', '-t', 'tags', '-p', '.', '-o', '/home/jespinal/.vim/plugged/vim-gutentags/res/ctags_recursive.options', '-x', 'vendor/*', '-x', 'themes/*', '-x', 'framework/thirdparty*', '-x', 'bootstrap-forms*', '-l', 'tags.log']
gutentags: In: /some/path/to/my/project/
...
gutentags: No specific project type.
gutentags: Finished ctags job.

From the previous output you can see that the shellscript update_tags.sh (which comes as part of vim-gutentags installation) is being called with ‘.’ as the path parameter (-p), which means that it is expecting patterns using relative file paths in order to pass it to ctags. Hence, if you use an absolute path it will not match what ctags is expecting.

So, instead of something like the following:

let g:gutentags_ctags_exclude = [
\ '/some/path/to/my/project/vendor/*',
\ '/some/path/to/my/project/themes/*',
\ '/some/path/to/my/project/framework/thirdparty*',
\ '/some/path/to/my/project/bootstrap-forms*'
\]

You should use something like this:

let g:gutentags_ctags_exclude = [
\ 'vendor/*',
\ 'themes/*',
\ 'framework/thirdparty*',
\ 'bootstrap-forms*'
\]

Afer all, this is due to how ctags behaves. If you issue the following command in your project directory, everything works fine:

ctags -f ~/tags -R --exclude=$PWD/vendor* --exclude=$PWD/themes/* --exclude=$PWD/framework/thirdparty/* --exclude=$PWD/bootstrap-forms* $PWD

But if you mix absolute paths ($PWD) with relative paths (“.”), chances are your “exclude” patterns will not be matched:

ctags -f ~/tags -R --exclude=$PWD/vendor* --exclude=$PWD/themes/* --exclude=$PWD/framework/thirdparty/* --exclude=$PWD/bootstrap-forms* .

So, there you have. Happy vim scripting!

Tagged , , , ,

1 thought on “vim-gutentags ignoring exclude parameters from ctags

Leave a Reply

Your email address will not be published.