Skip to content

Instantly share code, notes, and snippets.

@cyansprite
Last active December 13, 2017 08:29
Show Gist options
  • Save cyansprite/c35aa42d022aa36a0e8fdd4d42d3089a to your computer and use it in GitHub Desktop.
Save cyansprite/c35aa42d022aa36a0e8fdd4d42d3089a to your computer and use it in GitHub Desktop.
Nice fold text for vim.
"Result:
"........................................ Text Here ( x lines ) .........................................
function! SuperSexyFoldText() "{{{
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("%s", lines_count)
let foldchar = " "
let foldtextstart = strpart('' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
let foldtextend = ' ( ' . repeat(" ", 5 - len(lines_count_text)) . lines_count_text . repeat(" ", 2) . "lines" . ' ) '
let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
return '....' . repeat('.', winwidth('.') / 4) . " " . line . repeat(foldchar, winwidth('.') / 3 - len(line)) . foldtextend . repeat(".", winwidth('.'))
endfunction
set foldtext=SuperSexyFoldText()
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment