Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a plain text file that uses -- >8 -- as section separators, e.g.:

-- >8 --

first section
some content
more content

-- >8 --

second section
some content
more content

-- >8 --

In order to more easily navigate the file, I want to fold sections between markers. I was expecting that would be as easy as:

set foldmethod=marker
set foldmarker=--\ >8\ --,--\ >8\ --

But it results in nested folds.

I have found that I can use a fold-expression to achieve this (see answer below), but it seems rather excessive. Is there a simpler way of doing this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I've found that I can use a fold-expression to do this:

set foldmethod=expr
set foldexpr=(getline(v:lnum)=='--\ >8\ --')?1:2

Screenshot:

- -- >8 --
|++---  5 lines: first section------------------------------------------------
| -- >8 --
|++---  5 lines: second section-----------------------------------------------
| -- >8 --
share|improve this answer
1  
That's how I would do it, too. Doesn't look excessive to me. –  Ingo Karkat Feb 26 '13 at 9:02
    
@IngoKarkat: I guess you're right, I was just hooked up on the idea of having fold-marker do this. Thanks. –  Thor Feb 26 '13 at 9:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.