Skip to content

Instantly share code, notes, and snippets.

@Sammyalhashe
Created October 3, 2020 20:47
Show Gist options
  • Select an option

  • Save Sammyalhashe/d3c23559ae0cb6253d64091f941c065d to your computer and use it in GitHub Desktop.

Select an option

Save Sammyalhashe/d3c23559ae0cb6253d64091f941c065d to your computer and use it in GitHub Desktop.

Revisions

  1. Sammyalhashe created this gist Oct 3, 2020.
    12 changes: 12 additions & 0 deletions folding.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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()