My vim configuration
git clone https://github.com/m-col/vim-misc
Files | Refs | Readme

Commit de2e2944a1e6484464133ffbfb60652a696db10e
Parent: 8796da2cef07a7c47e048c886ffc10499bc288f1
Author: mcol <mcol@posteo.net>
Date: 2019-02-09 14:55:52 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2019-02-09 14:55:52 +0000

added generic filetype agnostic folding rules

plugin/folds.vim Added

@@ -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()