Would like to have all content of the folded block, instead of only the first line.

My current foldsettings are:

set foldmethod=marker
set foldmarker={,}

Example how my data is structured:


Current folds look like:

+--  5 lines: ---------------------------

Ideally folds look like:

{  cows  pigs  chickens  } --------------

Have searched on the net for a while, unfortunately didn't succeed.

  • That's not what I'd call folding. In VIm folding hides text/content. You're describing something different...compression or reformatting of text/content, I guess.
    – B Layer
    Jan 28, 2019 at 3:52

2 Answers 2


The option foldtext defines a expression, that is evaluated to create the text displayed for a closed fold. By default this is set to the build in function foldtext().

You can create a custom function, to create the text displayed on a closed fold. The documentation :help fold-foldtext contains an example. Note that the resulting text is truncated to fit window width.


An example of probably what you want:

enter image description here

set foldmethod=marker
set foldmarker={,}

set foldtext=MyFoldText()
fu! MyFoldText()
    let lineNr = v:foldstart
    let text = ""
    while (strlen(text) < winwidth(0) - v:foldlevel - 2) && lineNr <= v:foldend
        let text .= getline(lineNr).' '
        let lineNr += 1

    let text = v:folddashes . text
    if strlen(text) > winwidth(0) - 5 
        let text = strpart(text, 0, winwidth(0) - 5).' … }'
    return text

It is not 100% bulletproof, probably will make your vim slow. I could make it more generic (you see there are some figures I manually hardcoded) but I will leave it for you to tinker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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