> I have a file with folding enabled.
> What I would like to do is use something like this:
> But I only want this to operate on folds.
Well, it looks like you have two parts...the fold and the regexp.
You should be able to tweak something like either:
:v/dave/if foldlevel('.') > 0 | d | endif
which, on lines not matching "dave" and that are folded, should
be deleted. If you're only interested in folds that are
open/closed, you can use
foldclosed(line('.')) == -1
(or != if you want lines that *are* folded).
Alternatively, one could use
:folddoopen if getline('.')=~'dave' | d | endif
You can tweak
[=~ | !~]
foldlevel('.') [> | ==] 0
to get the magic combo of actions that you're looking for.
Ideally, one could do something like
but vim gripes about recursive use of ":g". One of those quiet
little wishes for a Vim enhancement I've long had, but am not
likely to get.
Various combos of these elements should allow you to perform Ex
actions over ranges that do/don't match a given regexp within
lines that are/aren't in defined folds (or are/aren't currently