Update, September 13th, 2011: I’ve made this into a Vim plugin.

Objective-C is fairly verbose, and while Kiwi does a great job as a domain-specific language for specifying your system, it can’t hide everything. Wouldn’t it be nice if you could just see your specification statements, and only see the code when you needed to?

This is what led me down the path of setting up vim folding for Kiwi specs. My first attempt was using http://vimdoc.sourceforge.net/htmldoc/fold.html#fold-marker and manually inserting {{ "{{{1" }} and {{ "{{{2" }} markers, with the occasional }}} marker when vim needed it to keep in sync. This quickly became messy. Bunches of curly braces all over the place got in the way of reading the specs, and it’s hard to create macros which know the correct fold levels.

I finally gave in and wrote this custom fold method. Kiwi constructs are all handled automagically, but it supports manual insertion of folds using the normal fold markers. I use this to fold support code at the top of the file.

Kiwi specs are now much more readable. (Though this screenshot reminds me that I’ve gotten used to Vim’s lack of support for the block syntax.)

Screenshot of folded Kiwi spec