My vim configuration
git clone https://mcol.xyz/code/vim-misc
Log | Files | Refs | README

commit de2e2944a1e6484464133ffbfb60652a696db10e
parent 8796da2cef07a7c47e048c886ffc10499bc288f1
Author: mcol <mcol@posteo.net>
Date:   Sat,  9 Feb 2019 14:55:52 +0000

added generic filetype agnostic folding rules

Diffstat:
Aplugin/folds.vim | 34++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)

diff --git a/plugin/folds.vim b/plugin/folds.vim @@ -0,0 +1,34 @@ +"------------------------------------------------------------------" +" Global folding rules +"------------------------------------------------------------------" + + +" format folded section header text +function! GenericFoldText() + let line = getline(v:foldstart) + + let nucolwidth = &fdc + &number * &numberwidth + let windowwidth = winwidth(0) - nucolwidth - 3 + let foldedlinecount = v:foldend - v:foldstart + + let onetab = strpart(' ', 0, &tabstop) + let line = substitute(line, '\t', onetab, 'g') + + let line = strpart(line, 0, windowwidth - len(foldedlinecount)) + let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + return line . repeat(" ",fillcharcount) . ' ' . foldedlinecount +endfunction +set foldtext=GenericFoldText() + + +function! GenericFolds() + if match(getline(v:lnum), '^\s*' . &commentstring[0] . &commentstring[0]) >=0 + return ">1" + else + return "=" + endif +endfunction + + +set foldmethod=expr +set foldexpr=GenericFolds()