Vim, CTAGS and PHP 5
I’ve just discovered CTAGS, thanks to theTop 10 things Vi user need to know about Vim list.
Ctags generates an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).
To use CTAGS with PHP 5, I downloaded the CTAGS source code, and this patch. Bascially the patch adds capabilities for the private, protected and public visibilty keywords.
# wget http://kent.dl.sourceforge.net/sourceforge\
/ctags/ctags-5.5.4.tar.gz
# tar -zxvf ctags-5.5.4.tar.gz
# wget http://svn.bitflux.ch/repos/public/misc/ctags-php5.patch
# mv ctags-php5.patch ctags-5.5.4
# cd ctags-5.5.4
Now patch the php.c file
# patch php.c ctags-php5.patch
Configure build and install CTAGS
# ./configure
# make
# make install
CTAGS is now installed, we can start to use it. I’d recommend creating tag file for different projects seperately, rather than one big one in your home folder or something. So move to your folder of choice and create the tags file.
# cd /path/to/your/project
# ctags -R
This may take a while depending on how many files you have. Once it is done, you’re ready to start using CTAGS with Vim. The ‘-t’ option for Vim opens the file containing that tag. So..
# vim -t 'MyClass'
… would open the MyClass.php class definition file. Once inside a file, hitting ctrl-] while the cursor is over a function/class name, Vim will attempt to open the file with that tag. Pressing ctrl-t will take you back a step.
Tags: vim ctags php








February 10th, 2009 at 10:38 pm
Nice post!! thanks a lot!
March 31st, 2009 at 10:02 am
Hello Dave,
Your link to the “top 10 things Vi user need to know about Vim” points to: http://www.oualline.com/10/top_10.html It should be http://www.oualline.com/vim/10/top_10.html.
Regards
Chris
March 31st, 2009 at 10:36 am
Cheers, updated
April 23rd, 2009 at 10:36 am
If the patch fails, try this:
wget http://templestowe.org/ctags-5.5.4-php5.patch
patch php.c ctags-5.5.4-php5.patch