Vim auto-generate ctags

au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &

The downside is that you won’t have a useful tags file until it completes. As long as you’re on a *nix system it should be ok to do multiple writes before the previous ctags has completed, but you should test that. On a Windows system it won’t put it in the background and it’ll complain that the file is locked until the first ctags finishes (which shouldn’t cause problems in vim, but you’ll end up with a slightly outdated tags file).

Note, you could use the --append option as tonylo suggests, but then you’ll have to disable tagbsearch which could mean that tag searches take a lot longer, depending on the size of your tag file.

Leave a Comment