Ctags with Vim for PHP5
One of the features I have missed since starting using Vim as my main source code editor is the ability to navigate a source file by its classes, properties and methods. I am aware of the existence of Ctags as a program for mapping source files and creating indexes accessible for use by text editors, but my experience has been up until recently that Ctags cannot correctly index PHP5 files - Ctags does not seem to understand the Private, Protected and Public precursors to the function arguments. However I have come across a patch - provided by Christian Stocker at bITFLUX that fixes this problem.
Patching and Installing Ctags
Christian says on his site that his patch works for Ctags 5.5.4 - I have tried it against version 5.6 and found no problems. Below is a brief run through of installing and patching Ctags on an Linux or Cygwin machine.
Firstly download and untar Ctags and Christian Stocker’s patch
# wget http://kent.dl.sourceforge.net/sourceforge/ctags/ctags-5.6.tar.gz # tar -xvf ctags-5.6.tar.gz # wget http://svn.bitflux.ch/repos/public/misc/ctags-php5.patch # mv ctags-php5.patch ctags-5.6
Next, it’s time to apply the patch to the Ctags php.c file.
# cd ctags-5.6 # patch php.c ctags-php5.patch
Next, configure the build and make install. Note the optional --prefix="/" - this is because I ran this particular example in Cygwin.
# ./configure --prefix="/" # make # make install # make clean
If everything made ok, try running the following:
# ctags --help
You’ll soon see that Ctags is a very powerful tool - there are many available arguments, though I’ll just use one of the two most commonly used commands here - the (-R) recursive command. There are several strategies for generating and using Ctags in projects, particularly when it comes to multi level directory hierarchies. You’ll find some help here on the Ctags Sourceforge FAQ here. I am using the ‘local tag file in each directory only for the source files in that directory’ method.
# cd /myprojects/project_a # ctags -R
Once Ctags has finished generating the tags file, you are in business and ready to start editing in Vim. So fire up Vim and open a PHP file. To see what Ctags has generated for the file, type TlistToggle in command mode and hit CTRL + w twice to change focus to the Ctags window. You can then navigate up and down the tree and hit enter to go straight to that point in the source file.
About this entry
You’re currently reading “ Ctags with Vim for PHP5 ,” an entry on chris ramsay
- Published:
- 10.24.06 / 11am
- Category:
- PHP, Programming, Vim










No comments
Jump to comment form | comments rss [?] | trackback uri [?]