Installing & using ctags in Vim


brew install ctags
cd project root
ctags -R .
# or if you want to keep the tags file out of site
ctags -R -f .git/tags .

then edit a file, put your cursor on an identifier and hit <Ctrl>-] to see it’s definition. Hit <Ctrl>-t to return to where you started.

How to update your ctags with git hooks

by the always amazing Tim Pope


in .git/hooks/ctags:

set -e
dir="`git rev-parse --git-dir`"
trap 'rm -f "$dir/$$.tags"' EXIT
git ls-files | \
  ctags --tag-relative -L - -f"$dir/$$.tags" --languages=-javascript,sql
mv "$dir/$$.tags" "$dir/tags"

then in post-commit,post-checkout,and post-merge you have:

.git/hooks/ctags >/dev/null 2>&1 &

make them all executable and Bob’s your uncle, which in England means that your ctags will be updated wheneever you commit, checkout or merge. Actually Tim puts it all in a template dir and git inits in his repo to install it which is smarter, but you get the idea. Read his post.