Improving my Vim environment with ctags and Tagbar

Improving my Vim environment with ctags and Tagbar

Hold on Cowboy

This blog post is pretty old. Be careful with the information you find in here. It's likely dead, dying, or wildly inaccurate.

I love Vim. There is something about it. Most people that “try” Vim, hate and wonder what all the fuss is about. If you force yourself to learn it, customize your environment and start using it, you’ll want to use it for all your text editing needs. Here are few more improvements I’ve installed today.

 

Tagbar

Tagbar allows you to see inspect the current file listing the properties and methods in that file. This works for both PHP and JavasScript (yes more too I’m sure).

Here’s how to install on OS X, I’m assuming you are using the wonderful Pathogen to install Vim plugins

cd ~/.vim/bundles
git clone https://github.com/majutsushi/tagbar.git
echo "nmap  :TagbarToggle" >> ~/.vimrc

Restart Vim, open a file in Vim and then press F8. That will open a window on the right of your screen showing Classes, Functions, and Variables. Clicking (or moving cursor over top of them and hitting enter) will move the cursor in the other window to the location.

Ctags

Ctags allow you to jump to the file of the classes you are calling, this was the one feature I really missed that PHPStorm did very well.

First you need to install ctags, I would recommend installing Mac Ports, then installing ctags with

port install ctags

After this you can generate your ctags for a project with

cd /your/project/directory/
ctags -R --languages=php .

Now you when the cursor is over a class name you can click Ctrl+] to jump to that file and Ctrl+T will jump back to the original file.

Simply Awesome.

Resources:

http://www.zalas.eu/jumping-to-a-class-function-and-variable-definitions-in-vim-with-exuberant-ctags http://haridas.in/vim-as-your-ide.html