help.vim (1135B) [raw]
1 " Some folding settings I like to use for writing Vim plugin documentation 2 " Won't work universally, but doesn't hurt to enable 3 4 " Simple fold function to fold until the next ===== or ------ 5 function! DocTxtFoldExpr(lnum) abort 6 if getline(a:lnum + 1) =~ '^\(=\+\|-\+\)$' 7 return '<1' 8 else 9 return 1 10 endif 11 endfunction 12 13 " Fold Text that prints number lines folded, a preview of what header it is, 14 " and the section name. Attempted to align nicely, but it breaks with tabs 15 " - 6 lines: ===== INTRO ..... 16 " - 12 lines: ----- Example ..... 17 function! DocTxtFoldText() abort 18 let l = getline(v:foldstart) 19 let lp1 = getline(v:foldstart + 1) 20 let num_lines = v:foldend - v:foldstart + 1 21 let lines_text = printf("%4s", num_lines) . ' lines:' 22 let header_preview = l[0:5] 23 let section_name = lp1[0:stridx(lp1, ' ')] 24 if section_name !~ ' $' 25 let section_name = section_name . ' ' 26 endif 27 return join([v:folddashes, lines_text, header_preview, section_name], ' ') 28 endfunction 29 30 setlocal foldexpr=DocTxtFoldExpr(v:lnum) 31 setlocal foldtext=DocTxtFoldText() 32 setlocal foldmethod=expr