ctags got you down?

http://farm4.static.flickr.com/3267/3161095736_042f71a9d7.jpg So for those of you using Vim, ctags are an extremely useful tool to have at your disposal. Join that with the rails.vim plugin and who needs Textmate. (OK, don’t flame me for that one.)

Setting up ctags is simple, now that we have homebrew:

brew install ctags

That’s it. Viva la brew!

Now go back to your rails project in Vim and issue the :Rtags command.

Whoops, that didn’t go as planned. You are probably seeing something like this:

invalid flag -- -R

What the heck I just installed ctags via brew, didn’t I? Well yes you did. The problem is that OSX has ctags installed already and is command blocking your awesome ctags implementation (which is actually exuberant tags).

If you were to issue the ctags command alone in the terminal you will see something like this:

usage: ctags [-BFadtuwvx] [-f tagsfile] file ...

That means you are still accessing the original ctags implementation on OSX. Turns out this is a simple fix. Just rename the ctags command in /usr/bin.

sudo mv /usr/bin/ctags /usr/bin/ctags_orig

Now if you reload your terminal or open a new window and initiate the ctags command, you should see something like this:

ctags: No files specified. Try "ctags --help".

Now you’re in business! Go back to your rails project in Vim and run the :Rtags command again. Now it should appear that the command completed. Give it a try. Go search for one of your methods. With the cursor on something you want to find, press and you should magically be transported to where the method is defined. Hooray!