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.
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:
tlhunter@mac:~ $ mkdir ctags; cd ctags tlhunter@mac:~/ctags $ curl -O http://www.thomashunter.name/wp-content/uploads/ctags-5.8.tar.gz tlhunter@mac:~/ctags $ tar xzvf ctags-5.8.tar.gz tlhunter@mac:~/ctags $ cd ctags-5.8 tlhunter@mac:~/ctags/ctags-5.8 $ ./configure tlhunter@mac:~/ctags/ctags-5.8 $ make tlhunter@mac:~/ctags/ctags-5.8 $ sudo make install
Note: I’m hosting ctags myself, because SourceForge isn’t friendly with downloading in the terminal.
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:
tlhunter@mac:~ $ sudo chmod a+r /usr/local/bin tlhunter@mac:~ $ sudo chmod a+x /usr/local/bin
You might not have to do this, but I did. For some reason my /usr/local/bin directory wasn’t browsable by my normal user account.
Now that Ctags is installed happily, it’s time to install the Tagbar plugin! Follow these terminal commands:
tlhunter@mac:~ $ cd ~/.vim tlhunter@mac:~/.vim $ git clone git://github.com/majutsushi/tagbar
Or, if you use pathogen:
tlhunter@mac:~ $ cd ~/.vim/bundles tlhunter@mac:~/.vim $ git clone git://github.com/majutsushi/tagbar
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.
let g:tagbar_ctags_bin='/usr/local/bin/ctags' " Proper Ctags locations let g:tagbar_width=26 " Default is 40, seems too wide noremap <silent> <Leader>y :TagbarToggle " Display panel with y (or ,y)
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.