Noiseless fold text

2 Points

Ory Band Ory Band

9 years ago

Fold text without trailing dashes - and fold line count

" The trailing '" {{{' is just to force folding on this function,
" since I `set foldmethod=marker` on `vim` file type.
function! FoldText() " {{{
    let line = getline(v:foldstart)

    let nucolwidth = &fdc + &number * &numberwidth
    let windowwidth = winwidth(0) - nucolwidth - 3

    " expand tabs into spaces
    let onetab = strpart('          ', 0, &tabstop)
    let line = substitute(line, '\t', onetab, 'g')

    let line = strpart(line, 0, windowwidth - 2)
    let fillcharcount = windowwidth - len(line)

    return line . repeat(" ", fillcharcount)
endfunction " }}}

set foldtext=FoldText()