Neither one nor Many

december 29 2012

To everybody that contacted me, and whom I didn't reply to from my hotmail address: please read this, I had problems with the Hotmail Junk filter *again* sorry!

This script can fold PHP functions and/or classes, properties with their PhpDoc, without manually adding marker style folds ({{{ and }}}). It will fold stuff into something like the following screenshot.


  • It remembers fold settings. If you add functions and execute the script again, your opened folds will not be closed.
  • It will not be confused by brackets in comment blocks or string literals.
  • The folding of class properties with their PhpDoc comments.
  • The folding of all class properties into one fold.
  • Folding the original marker style folds too.
  • An "**" postfixing the fold indicates PhpDoc is inside (configurable).
  • An "**#@+" postfixing the fold indicates PhpDocBlock is inside (configurable).
  • Empty lines postfixing the folds can be configured to be included in the fold.
  • Nested folds are supported (functions inside functions, etc.)


  • Better 'configurability' as opposed to editting the PHPCustomFolds() function and some "Script configuration" global variables.


This script is tested successfully with Vim version >= 6.3 on windows and linux (With 6.0 it works sometimes, I don't recommend using it in that version)

But I'd recommend using a new vim, at the time of writing 7.3 works fine with it!

spf13's vim distribution

You can also install spf13's vim distribution (if you like it). phpfolding.vim is included in this package too. I'm testing it out at the moment, like it so far. Kind of missed my mappings though, so I still added <F5>, <F6> and <F7> to my .vimrc.

Also I noticed EnableFastPHPFolds gives better results now better than EnablePHPFolds, this is what I experienced at work anyway, with vim 7.3. This used to be the other way around..


  1. Put phpfolding.vim in your plugin directory (~/.vim/plugin)
    i.e., wget:
  2. You might want to add the following keyboard mappings to your .vimrc:
    map <F5> <Esc>:EnableFastPHPFolds<Cr>
    map <F6> <Esc>:EnablePHPFolds<Cr>
    map <F7> <Esc>:DisablePHPFolds<Cr>
  3. You might want to add the following lines to php.vim in your after/ftplugin directory (~/.vim/after/ftplugin/php.vim), this will be executed after opening a .php file:
    " Don't use the PHP syntax folding
    setlocal foldmethod=manual
    " Turn on PHP fast folds
  4. It might be necessary that you load the plugin from your .vimrc, i.e.:
    let php_folding=0
      (if you can't use the after directory in step 3)
    source ~/path/to/phpfolding.vim
      (if you're not using the default plugin directory)

Known issues

  1. C++ style commented brackets can still interfere with the bracket matching.
    For example comments like are not recognized as comments: // old: for (...) {
    Whereas C-style comments are, e.g.: /* old: for (...) { */
  2. The following won't be matched with the Regex in FindFoldStart():
    function (...,
    ) {
    Though Steve McConnell (writer of Code Complete) would ask why you'd need more then two lines for function parameters :)

Note: My Hotmail Junk filter probably ate a some e-mails I received from

I use my hotmail address for accounts where my e-mail is publicaly displayed, like in my profile page on (I don't want spam in my primary e-mail inbox). So I only check my e-mail this hotmail address every now and then, probably every 6 months and it's full of stuff spam so I could have easily missed e-mails regarding phpfolding. I discovered in 2010 that there was feedback in my Junk filter, so I turned the Junk filter off, anyways that's how I remember it (and how I wrote it down). Now in 2012 I check the Junk filter again, and there is another email. Junk is automatically deleted after X days, so who knows how many mails I might have missed.

Really don't understand why it got into Junk, this specific person wrote hello, introduced himself, said something nice and signs off the e-mail. All in normal letter formatting, no URL's or e-mail addresses used, no images, just plain text. It was a valid gmail address, there were no weird Headers, and it was sent from gmail itself not some other smtp server...

You can contact me here by commenting, or send me an e-mail to the new one I use in my profile at

Webdevelopment Comments (0)

Leave a Reply

Ray Burgemeestre
february 23th, 1984

C++, Lisp, Music, Philosophy

Other interests:
Music, Art, Zen, Webdevelopment