How to automatically update tag file?

I would to know from your experiences on using Vim how do you manage to maintain tags file of a Rails project up to date while you are writing codes(renaming methods, adding new methods) in Vim? Or you just run ctags by manually when it’s out of sync?

@samnang, this is the best system I’ve seen to do this:

It’s Tim Pope ™ approved, and requires a little bit of one-time upfront set up on your machine, but then handles every git repo on your system automatically.

I would recommend continuing to have a ctags alias in zsh and vim for refresh, because the above approach happens when you commit, so you might want to refresh your tags between commits.

Our own @christoomey wrote this:

Thanks for the mention @benorenstein, but credit is actually due to @pat as my repo is just a fork of his: Overall I’ve found it to be a solid solution, but do make sure you configure it to ignore your home directory and dotfiles as they can cause timeouts.

The plugin will run Ctags on Vim’s Bufenter event. If you want more frequent updates you could hook it up to run on each write with:

Plugin 'pbrisbin/alt-ctags'
autocmd BufWritePost * Ctags

I’ve toyed with a few other approaches, but @pat’s alt-ctags is the best and simplest solution I’ve found yet.

1 Like

FWIW: I’ve actually switched to (a small variation) on the tpope method.