Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


- -- >8 --
|++---  5 lines: first section------------------------------------------------
| -- >8 --
|++---  5 lines: second section-----------------------------------------------
| -- >8 --
share|improve this answer
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


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.