Created
October 3, 2020 20:47
-
-
Save Sammyalhashe/d3c23559ae0cb6253d64091f941c065d to your computer and use it in GitHub Desktop.
Fancy folding in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment