Comfortable PHP editing with VIM -4- - Blog - Open Source - - php, photography and private stuff

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!

If you liked this blog post or learned something, please consider using flattr to contribute back: .



Add new comment

Fields with bold names are mandatory.