I'm currently using Vim to edit PHP files and would like to implement code folding for functions only. I've tried setting the foldmethod=expr
and using a regex with foldexpr
in my .vimrc file. The problem is i don't fully understand how foldexpr
is using the regex to apply folding to the source code and i can't seem to get it right.
Basically i want all PHP functions (inside classes too) to be folded and that's it. The nearest i've got is:
set foldexpr=getline(v:lnum-1)=~'function'?'>1':'='
but it's not right and i want to see if i can be a little more intelligent with the curly braces.
Any ideas?
IIRC folding do not work with regexes because it will slow vim down. You might get what you want by using foldmethod=indent and set foldnestmax to limit the number of nested folds created.