Question

I'm putting together a syntax for editing Java Manifest files (at github, if anyone's interested). I'm trying to collapse multiple single-line-comments (which I'm matching at the moment with syntax match manifestComment "#.*"). However, if I try to use a syntax region, then the entire file is marked and the entire thing collapses.

What I'm trying to achieve is this:

# A comment
# Another comment
# A third comment
Manifest-Version: 1

and have it collapse down into:

+--  3 lines: # A comment ----
Manifest-Version: 1 

The problem is that there's no distinct 'end' character, and the fold syntax doesn't help; so I can't do syntax region commentBlock start="^#" end="^[^#]". Roughly, the syntax region should start from the first hash character, and then continue down the lines until it finds a line which doesn't begin with a hash.

Was it helpful?

Solution

:set foldmethod=expr
:set foldexpr=getline(v:lnum)[0]==\"#\"

For information, :h fold-expr.

OTHER TIPS

How about syntax region commentBlock start="^#" end="^#\@!"?

The \@! is like (?!pattern) in Perl, i.e. it matches with zero-width if the preceding atom -- # in this case -- does not match at the current position.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top