" Vim folding file " Author: Jorrit Wiersma (foldexpr), Max Ischenko (foldtext) " Last Change: 2004 Jun 30 " Version: 2.2 setlocal foldmethod=expr setlocal foldexpr=GetGtdFold(v:lnum) setlocal foldtext=GtdFoldText() highlight Folded term=bold ctermfg=white ctermbg=black " highlight FoldColumn term=bold cterm=bold function! GtdFoldText() let line = getline(v:foldstart) let line3 = substitute(line, '\t', ' ', 'g') let line2 = substitute(line3, '^\( *\)', '&+ ', '') let items = v:foldend - v:foldstart "let nextline = getline(nnum) "let sub = substitute(nextline, '^[ \t]*', '', '') "let action = items > 0 ? '... and ' . items . ' more' : '' "let nextline = ' (' . sub . action . ')' let action = items == 1 ? 'action' : 'actions' let nextline = ' - ' . items . ' ' . action . ' ' return line2 . nextline endfunction function! OldGtdFoldText() let line = getline(v:foldstart) let items = v:foldend - v:foldstart let sub2 = substitute(line, '\t', ' ', 'g') let sub = substitute(sub2, '^\( *\)', '&+ ', '') let action = items == 1 ? ' action ' : ' actions ' return sub . ' - ' . items . action endfunction function! GetGtdFold(lnum) let ind = indent(v:lnum) " Ignore blank lines if line =~ '^\s*$' return "=" endif " The end of a fold is determined through a difference in indentation " between this line and the next. " So first look for next line let nnum = nextnonblank(v:lnum + 1) let nind = indent(nnum) if nind > ind return ">" . (ind / &sw + 1) endif " If the next line isn't blank, we probably don't need to end a fold " if nnum == v:lnum + 1 " return "=" " endif " If next line has less indentation we end a fold. " This ends folds that aren't there a lot of the time, and this sometimes " confuses vim. Luckily only rarely. if nind < ind return "<" . (nind / &sw + 1) endif " If none of the above apply, keep the indentation return "=" endfunction