VIM Tutorials

VIM as a PHP IDE

I’ve open sourced and hosted my VIM configuration on github. It’s configured to work more like an IDE and less like a text editor. With features like file browsing and listings of classes, functions/methods, and variables/properties, it does a pretty good job! I mostly run this setup with MacVIM, but it runs fine in other operating systems with a small amount of tweaking.

Browse my VIM PHP IDE configuration files!

Using Swipes in MacVIM in OS X

The awesome folks working on MacVIM have a convenient way for hooking into the OS X swipes for performing VIM actions. All you need to do is map the <SwipeLeft> and <SwipeRight> inputs to a vim action!

The following chunk of VIM commands are copied from my personal .vimrc file. I’ve wrapped everything specific to configuring MacVIM inside of a conditional statement. The reason for this is my config file is shared across different environments, and trying to map the swipe actions in a linux terminal isn’t going to make a lot of sense.

if has("gui_macvim")
    set transparency=15            " Makes the background window 85% opaque
    set guifont=Monaco:h10         " Monaco 10 is my favorite font
    set noantialias                " Especially when it isn't aliased
    map  :bprev     " Swipe left opens a previous hidden buffer
    map  :bnext    " Swipe right opens the next hidden buffer
endif

You’ll see that I’ve got the swipes setup to use the bprev and bnext commands. These are provided by the buftabs plugin. You can, of course, map these to any other VIM command you would like to use.

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

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:

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.

 Scroll to top