abstract
| - The foldtext function below does three things:
* Is less intrusive when displaying code, and right-aligns the number of lines in the fold.
* Collapses folds that start and end on braces with everything between the braces replaced with {...}.
* Tries to collapse multiline comments with the first non-blank line in the comment. Outstanding issues:
* Right alignment may not work with signs turned on.
* Tabs mess up the in-place display of the initial '{'. " Set a nicer foldtext function set foldtext=MyFoldText() function! MyFoldText() let line = getline(v:foldstart) if match( line, '^[ ]*\(\/\*\|\/\/\)[*/\\]*[ ]*$' ) == 0 let initial = substitute( line, '^\([ ]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' ) let linenum = v:foldstart + 1 while linenum < v:foldend let line = getline( linenum ) let comment_content = substitute( line, '^\([ \/\*]*\)\(.*\)$', '\2', 'g' ) if comment_content != '' break endif let linenum = linenum + 1 endwhile let sub = initial . ' ' . comment_content else let sub = line let startbrace = substitute( line, '^.*{[ ]*$', '{', 'g') if startbrace == '{' let line = getline(v:foldend) let endbrace = substitute( line, '^[ ]*}\(.*\)$', '}', 'g') if endbrace == '}' let sub = sub.substitute( line, '^[ ]*}\(.*\)$', '...}\1', 'g') endif endif endif let n = v:foldend - v:foldstart + 1 let info = " " . n . " lines" let sub = sub . " " let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' ) let fold_w = getwinvar( 0, '&foldcolumn' ) let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 ) return sub . info endfunction I also use the following highlights with white backgrounded source to visually set the folds apart from non-folded lines, while trying to keep a nice aesthetic. highlight FoldColumn gui=bold guifg=grey65 guibg=Grey90 highlight Folded gui=italic guifg=Black guibg=Grey90 highlight LineNr gui=NONE guifg=grey60 guibg=Grey90
|