Cover image for post Comfortable PHP editing with VIM -4-

Comfortable PHP editing with VIM -4-

It's nearly 4 month ago now, since I last blogged about my .vimrc (the main Vim config file) and the recent enhancements I added to it. This time, I go a step further as in the last 3 parts: I wrote my first own Vim script. :) Beside that there are as usual some other great enhancements and tips I collected over the past 4 month and I already have an idea of how to proceed and what I need more. But first, I'd like to give a brief changelog between version 1.3 and the last version:

  • Fixed bug with cover char mapping of "" in visual mode.

  • Mapped ; in command mode to check if the current line ends with a semicolon and to add it, if it's missing.

  • Configured :make command to run "php -l" and jump to the line of the first compile error afterwards.

  • Added setting for not highlighting every search result (which is a Gentoo standard setting).

  • Added laststatus=2 which makes a nicer ruler (thanks Derick!).

  • Moved PHP specific settings to a file type plugin in .vim/ftplugins/php.vim (only global options are left in the .vimrc itself).

  • Activated automatic sourcing of ftplugins (so that the php.vim is included for PHP files).

  • Added file type setting for .phps files to PHP.

  • Added possible alternatives for other coding standards for mappings of {} and ().

These changes are mostly of cosmetic nature and the real enhancement is the script I wrote. I was searching for a longer time for a really convenient documentation plugin to let Vim generate phpDoc conform doc blocks for my classes/functions/methods/... . Sadly I did not find anything beside the scripts by Karl Heinz Marbaise and Vidyut Luther, which both did not satisfy my needs or even almost work. So I started hacking around in Vidyut's script to fix it and the result was PDV (phpDocumentor for Vim), a complete rewrite. PDV version 1.0.0 supports the following features:

  • Generation of phpDocumentor conform docs for

    • Classes

    • Methods/Functions

    • Attributes

  • Supporting for PHP 4 and 5 syntax elements.

  • Define default values for phpDocumentor tags like @version (I use $id$ here), @author, @license and so on.

  • For function/method parameters and attributes, the script tries to guess the variable type as good as possible from PHP5 type hints or default values (for array, bool, int, string...).

  • Generating doc blocks for single lines, all known elements in a visual selection and over a whole file (where in the latter cases existing documentation is taken into account).

I'll provide a copy of this script with my blog series in combination with my .vimrc and the FTPlugin, but maintain the script itself independantly on More features will surely come soon (I already planned support for constants and some other constructs, as well as documenting whole directories and some more stuff)!

You can download my actual .vimrc-package (since it's no more only a single file) here (CAUTION: If you already have a .vimrc, don't extract this package directly to your home diretory!).

Last for today, some tipps for using Vim:

  • All those enhancements (especially auto-indent and close char mapping) make it more or less impossible to paste text from other application to Vim. Thanks to Derick who showed my the settings ":set paste"/":set nopaste", which switch all enhancements off for insert mode.

  • Jakob Westhoff (from our local user group) told me about the combination <z>+<f> in visual mode, which wraps the selected parts into Vim fold-tags. Sadly this does not create the tags like I want it by now, but I guess I can change that somehow.

Hope you like it, 'till next time!

P.S.: I'll maybe write an extended entry for this one, when I find time, to explain the features in detail.


Because of so many questions about it: The link to my .vimrc above is outdated. Please refer to my SVN repository for a recent version!


[/quote] Mapped ; in command mode to check if the current line ends with a semicolon and to add it, if it's missing. [/quote]

Hej funny. I had the same idea some weeks ago, but i didn't think to include a check. Good idea - i will implement this as well. Nice work.

Cheers jerik

PS: Vim Rules !!

jerik at 2005-09-17

nice work man. I found a little bug in PDV! when my parent class named with underscore like OSC_Model PDV generate incorrectly result.

please add folding capabaliti for your wonderful PDV, Tanks.

PS: Sorry for my bad english ;-(

armen at 2005-10-03

Hi, nice idea about the ';' map :]. Here's another mapping to show the result inside Vim window ^_^

Charles at 2005-12-05

thank you for all of this... i will have to study that fore several evenings.

you might just want to add the following lines into the general purpose .vimrc ... that way, you have standard syntax hiLight on, when editing files non specified by the files in the .vim/ftdetect ...

such as the .vimrc itsel ;)

caillou at 2006-01-31

does this correctly handle syntax-coloring "less-than sign", "greater-than sign", and -> occuring within php blocks?

jm3 at 2006-09-30

AKA, does it correctly color "ASP-style" tags in PHP?

jm3 at 2006-12-01

Nope, I don't think so. Do not use them! Just use the correct PHP tags!

Toby at 2006-12-01

Oh. Why do you suggest not using them? They are easier to type, compatible with JSP & ASP, and PHP has supported them just fine since version 3.0.4.

jm3 at 2006-12-01

Because you are writing PHP, not ASP or JSP. :) Additionall, if you write an application for more than personal use (distribution, open source, custumers,...) you can never be sure that a server your application is deployed to supports them. So your application becomes a lot less portable.

Beside that, (almost?) all major PHP projects discourage all other tags except the official PHP tags and it is commonly considered good coding manor to use those.

Toby at 2006-12-01

Another side note: ASP tags will be gone in PHP 6. See

Toby at 2006-12-01

The download link for your .vimrc package is broken?

Francis Reyes at 2006-12-04

Please download it from SVN: Beware, I splitted the .vimrc to the actual file and the FTPlugin in addition (.vim/ftplugin/).

Toby at 2006-12-04


Francis Reyes at 2006-12-04

Sorry, that is only for web access. Checkouts can be done like this:

svn co svn://

That is because I run Lighttpd and not Apache. ;)

Toby at 2006-12-05

I love your series, but I never manage to get the command mappings to work.

When I try to write f.x. =roc nothing happens. I believe I've got some simple thing wrong here. Does anyone have a tip on how to debug command mappings?

Also, have you looked at this script for autoindenting php?

Tarjei Huse at 2007-02-17

Note that PDV is now named VIP and hosted on github. For details, please refer to

Toby at 2010-02-16