There are several problems:
- From
:help /\@!
: "You can't use "\@!" to look for a non-match before the matching position". Use\@<!
, include the possible characters in between in there, and drop the useless (because it's not anchored) non-greedy first match. - The
:global
command places the cursor on the first column of matching lines, so add a$
to make the%
work all the time. - Subsequent inner folds must be defined with the outer fold open:
zv
.
Ergo:
:%g/\%(class.*\)\@<!{$/normal! $zvzf%