How to set up ctags (go to definition) in Atom text editor

author image
By Ben Radler

Have you ever wished github's awesome Atom text editor had better support for jumping straight to a class or method definition like Rubymine or Sublime Text? Me too! So, here's a short set of instructions how to get this functionality working on OS X!

To summarize what we're going to do:

  • Install exuberant ctags from homebrew
  • Install an rbenv plugin and a gem that automatically generates ctags for rubygems
  • Let git know that you want to include the ctags binary and your new hooks in all git tracked repos
  • Create a ctags binary that generates a tags file for each project, and a few git hooks to keep our tags files up to date
  • Ensure your git-tracked repos have the newly created hooks and ctags binary
  • Install a helper package in Atom called autocomplete-ctags
  • Profit!

Quick & Dirty

My good friend Tyler Davis turned this entire post into an awesome setup script if you'd like to avoid doing these steps manually!

note: if you’ve ever installed atom-ctags, remove it, and delete any tags or .tags files from your project repos, or you’re gonna have a bad time

Steps

  1. Install exuberant ctags

    Open your terminal and type:

    brew install ctags
    
  2. Install the rbenv plugin and ctags gem

  3. Configure your git template directory

    # create a git template directory in your home directory
    mkdir -p ~/.git_template
    
    # tell git you want to use this directory to copy "template" files into all new git repos
    git config --global init.templatedir '~/.git_template'
    
    # tell git you want to alias a command `git ctags`
    git config --global alias.ctags '!.git/hooks/ctags'
    
  4. Copy my ctags binary and hooks files

    Download all of the hooks files and the ctags binary from here:

    https://github.com/Lordnibbler/dotfiles/tree/master/git_template/hooks

    And copy them into your git template directory (probably at ~/.git_template). These hooks trigger a run of git ctags whenever you move between branches, commit, etc., so your tags file is always up to date!

  5. Add git ctags command to your .gitconfig

    # tell git you want to alias a command `git ctags`
    git config --global alias.ctags '!.git/hooks/ctags'
    
  6. Install the atom package

    apm install autocomplete-ctags
    
  7. cd to a git-tracked project directory

    # run this command to copy your hooks and ctags binary to the repo
    # don't worry, it won't blow away your commit history or do anything destructive!
    git init
    
    # to seed it once, just to prove it works
    run `git ctags`
    
  8. Ensure symbols-view package is enabled in Atom!

  9. Relaunch Atom once

  10. Profit by using the go to definition feature in Atom!

Questions? Comments? Problems? Improvements? Anything??? Comment below and tell me, and I'll do my best to help!

author image

Ben Radler

Ben is a Software Engineer. He works on autonomous vehicle dispatch at Cruise.

© 2024 benradler.com. I love you.