Have you seen the "fold-expr" section?
EXPR *fold-expr*
The folds are automatically defined by their foldlevel, like with the "indent"
method. The value of the 'foldexpr' option is evaluated to get the foldlevel
of a line. Examples:
This will create a fold for all consecutive lines that start with a Tab: >
:set foldexpr=getline(v:lnum)[0]==\"\\t\
It seems like you could adapt this to the comment style in your files.
You could use the foldlevel() sorta like:
let &foldexpr = 'getline(v:lnum)[0]=="#"'
Fold all comments beginning with #
g/.*/ if foldlevel(line(".")) > 0 | s/$/ !!!/ | endif
Do something for each line that is folded
Change s/$/!!!/ to delete if you want to delete the folded lines.
On 4/29/06, cga2000 <[EMAIL PROTECTED]> wrote:
Is there any way I could use folding to do this:
1. Fold all lines in a file that contain only comments.
2. Optionally delete all the lines that have previously been folded.
I have a feeling I am looking for something less sophisticated than the
fold feature where I could remove all lines that contain a given pattern
- say, # or /* in col. 1, from a buffer and I am not sure folding is
the feature I should be looking at.
An example of possible use:
I would find this useful when trying to prune some configuration file
that has some ten lines of comments for every entry so that I can have
more or less the entire configuration file fit on one screen instead of fifteen
or twenty.
A more general definition of this need/problem might be to 'remove all lines
that match a certain pattern from the buffer - and optionally from the file
itself'.
Thanks.
cga