How to change the way that vim displays collapsed/folded lines

5

How can I change the way that vim displays those collapsed/folded lines? I would like it toshow hidden line numbers at line tail but not the head. I have googled and searched vim wiki but found no hints.

more pretty vim fold format

The fold style is just like the right hand side of the pic.

pambda

Posted 2015-10-22T12:24:30.030

Reputation: 238

After looking at ":help fold-foldtext" I don't think what you want is possible without patching the Vim core code. – Heptite – 2015-10-22T21:40:58.717

Answers

9

You could play with the method described in this blog post:

function! NeatFoldText()
    let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
    let lines_count = v:foldend - v:foldstart + 1
    let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
    let foldchar = matchstr(&fillchars, 'fold:\zs.')
    let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
    let foldtextend = lines_count_text . repeat(foldchar, 8)
    let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
    return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
endfunction

set foldtext=NeatFoldText()

There are many, variants, actually; and there's even a vimcast on that very subject.

romainl

Posted 2015-10-22T12:24:30.030

Reputation: 19 227