Reminder to myself: how to setup ctags for Ruby development in Vim, to keep updated tags files for projects, gems and Ruby standard library.

Project tags

Setup git to regenerate ctags index when working tree changes

Create ~/.git_template/hooks/ctags and mark it as executable:

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"

Create post-commit, post-merge and post-checkout hooks with the same content:

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

Create a post-rewrite hook:

case "$1" in
  rebase) exec .git/hooks/post-merge ;;

Setup global hooks templates for git

git config --global init.templatedir '~/.git_template'
mkdir -p ~/.git_template/hooks

Now every new project, cloned or created, will have these templates.

For existing repositories, use git init to safely copy these templates in them.

Gem tags

Automatically generate ctags for your gem on installation

Install gem-ctags RubyGems plugin to automatically invoke ctags on gems as they are installed:

gem install gem-ctags

Prm a one-off indexing of the gems that are already installed:

gem ctags

Install bundler.vim, so Vim will be aware of all tags files from all gems in the bundle.

Standard library tags

Install rbenv-ctags rbenv plugin to automatically generate new indices when a new Ruby interpreter is installed via rbenv.

mkdir -p ~/.rbenv/plugins
git clone git:// ~/.rbenv/plugins/rbenv-ctags
rbenv ctags

Install vim-ruby and vim-rbenv, so Vim will use tags files in the Ruby $LOAD_PATH.

Optionally, install rbenv-default-gems to automatically install gem-ctags for every new Ruby version. Put it at the top of ~/.rbenv/default-gems so that it indexes all gems underneath it.