paperlined.org
apps > vim
document updated 14 years ago, on Jul 21, 2009
'foldexpr' is one of the six methods for determining where folds are. IMHO, it's one of the most useful and versatile methods. However, they can be frustrating to understand/write/debug.

Documentation

Useful examples

" lines that match this pattern mark the START of a new [top-level] fold
:set foldmethod=expr | set foldexpr=(getline(v:lnum)=~'pattern')?'>1':'=' | set foldlevel=0 | 1

" lines that match this pattern are EXCLUDED from any folding  (sort of like a "grep" -- it displays only the lines that match the given pattern)
:set foldmethod=expr | set foldexpr=getline(v:lnum)!~'pattern' | set foldlevel=0 | 1