Installing VIM Tagbar with MacVIM in OS X

If you’re like me, you’re always hunting down a better way to do things, constantly testing IDE’s, text editors, Linux distributions, etc. I personally finally settled on VIM, but am still tweaking it every single day. Before using VIM, I was using Netbeans all the time as my IDE. Because of this, I’m always trying to make VIM more like an IDE. This is one of those tweaks which will make your VIM act more like an IDE.

This works with the latest version of MacVIM (61), I’ve even done it with an older version (59). We’ll be using the latest Ctags (5.8) and the latest Tagbar (2.1), and I’m sure the following steps will work fine as newer versions of these software come along.

NERDTree and TagBar in VIM

Here is a screenshot of my VIM setup (click it to make it bigger). On the right you will notice the Tagbar plugin. On the left you’ll see NERDTree. In the center, ugly WordPress code (well, this file is ok, but most sucks. I digress.)

To get Tagbar working on your Mac, you will need to install Exuberant Ctags, compile it, and install it. Don’t freak out yet! It’s not a pain in the butt like a lot of software and you shouldn’t get any scary errors during installation (assuming you’ve installed Xcode and friends, it’s on the second installation CD that came with your mac, or you can get it in the app store I believe for free). Follow the following steps in a terminal to get Tagbar running:

You’ve now downloaded, compiled, and installed ctags on your computer! However, we’ve put the ctags binary in the /usr/local/bin/ directory, while the main ctags provided by Apple is located in /usr/bin/. This is actually a good thing, because when OS X updates and overwrites all of the existing files used by the operating system, our awesome newer version of ctags will remain safe.

Type /usr/local/bin/ctags into your terminal and press enter. If you get a permission denied message, run the following commands:

Now, you’ll want to configure Tagbar to use the version of Ctags that we downloaded and compiled, not the version shipped with OS X. Edit your VIM configuration file (nano ~/.vimrc or something similar) and add the following lines.

If you had VIM open, you’ll want to restart it. You can now press your leader key (defaulted to ), followed by the letter “y”. You should have a list of the functions, classes, and variables used in the current file visible on the right.

Related Posts

Thomas is the author of Advanced Microservices and a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.

You seem to be using the terms “Tagbar plugin” and “Taglist plugin” interchangeably in this article. In fact, there are two different plugins, Taglist and Tagbar, which provide similar functionality. The Tagbar plugin is much nicer than Taglist, in my opinion.