Tuesday, May 15, 2012

Exuberant CTAGS in OSX 10.7

A killer feature essential to any developer is the ability to navigate projects quickly by jumping to function definitions from anywhere in code. Many IDEs come with such features. For us Vim users, we can achieve this by using ctags.

Installing Exuberant CTAGS

The original ctags comes installed by default in OSX. We want ctags-exuberant. The easiest way to install it is to use one of OSXs package managers. I use Homebrew:

brew install ctags-exuberant

If this doesn't work, you can install it directly from source by going to the ctags website. At the time of writing this article, the latest is ctags-5.8. Now go to the directory of your download and run the following commands:

tar xzvf ctags-5.8.tar.gz
cd ctags-5.8
./configure
make
sudo make install

If everything worked, you should be able to see 2 (or possibly more) versions of ctags by typing:

which -a ctags

/usr/bin/ctags ==> original ctags
/usr/local/bin/ctags ==> exuberant ctags

Tell OSX to use Exuberant CTAGS

Now, we just tell OSX which ctags to use by adding this to your .bash_profile:

export PATH="/usr/local/bin:$PATH"

Just open a new terminal and verify that the correct version of ctags is at the top of the list when you run:

which -a ctags

/usr/local/bin/ctags ==> exuberant ctags, YAY!
/usr/bin/ctags ==> original ctags

Using Exuberant CTAGS in Vim


To use the amazing Ctrl+] functionality in Vim, all you have to do is navigate to your project's root directory and run:

ctags -R .

This will create all the tags files necessary for Vim to use. Now, you can jump around function definitions easily right in Vim!

Resources:
Installing Exuberant CTAGS from source: http://adamyoung.net/Exuberant-Ctags-OS-X/

10 comments:

  1. Thanks a lot. Your instructions were very helpful

    ReplyDelete
  2. thanks a lot!!!!!

    ReplyDelete
  3. Nice instructions. Helped a lot.

    ReplyDelete
  4. Very easy to install!. Thanks a lot :-)

    ReplyDelete
  5. If you use Mac Ports:

    sudo port install ctags

    ReplyDelete