dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit 614af6b3c3b1aeb7e2673f18741a806cebc6676c (patch)
parent 018b75ffe6822b9073092e1e5c07a7e1ee55f7c2
Author: Alexander Karle <akarle@umass.edu>
Date:   Wed,  7 Nov 2018 23:58:20 -0500

vim: Add custom folding for help doc in Vim

This is particularly useful for writing my own doc.

Diffstat:
Avim/ftplugin/help.vim | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/vim/ftplugin/help.vim b/vim/ftplugin/help.vim @@ -0,0 +1,32 @@ +" Some folding settings I like to use for writing Vim plugin documentation +" Won't work universally, but doesn't hurt to enable + +" Simple fold function to fold until the next ===== or ------ +function! DocTxtFoldExpr(lnum) abort + if getline(a:lnum + 1) =~ '^\(=\+\|-\+\)$' + return '<1' + else + return 1 + endif +endfunction + +" Fold Text that prints number lines folded, a preview of what header it is, +" and the section name. Attempted to align nicely, but it breaks with tabs +" - 6 lines: ===== INTRO ..... +" - 12 lines: ----- Example ..... +function! DocTxtFoldText() abort + let l = getline(v:foldstart) + let lp1 = getline(v:foldstart + 1) + let num_lines = v:foldend - v:foldstart + 1 + let lines_text = printf("%4s", num_lines) . ' lines:' + let header_preview = l[0:5] + let section_name = lp1[0:stridx(lp1, ' ')] + if section_name !~ ' $' + let section_name = section_name . ' ' + endif + return join([v:folddashes, lines_text, header_preview, section_name], ' ') +endfunction + +setlocal foldexpr=DocTxtFoldExpr(v:lnum) +setlocal foldtext=DocTxtFoldText() +setlocal foldmethod=expr