commit 9d4dca87d7a3e1dd861edf8aabea9ba52d508b93 (patch) parent c60f6ea853d2d5001bb7b60d24d9393aff83ba90 Author: Alexander Karle <akarle@umass.edu> Date: Fri, 28 Sep 2018 23:09:12 -0400 [vim] custom VimL folding by expression I've been reading a good bit of VimL, and folds just make life easier! Diffstat:
M | vim/ftplugin/vim.vim | | | 23 | +++++++++++++++++++++-- |
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim @@ -1,2 +1,21 @@ -" allow vim style folding -setlocal foldmethod=marker +" Custom folding by expression to fold markers and functions + +let b:viml_fold_markers = split(&foldmarker, ',') + +function! VimLFoldByFunctionAndMarker(lnum) abort + let l = getline(a:lnum) + if l =~ '^function' + return 'a1' + elseif l =~ '^endfunction' + return 's1' + elseif l =~ b:viml_fold_markers[0] + return 'a1' + elseif l =~ b:viml_fold_markers[1] + return 's1' + else + return '=' + endif +endfunction + +setlocal foldmethod=expr +setlocal foldexpr=VimLFoldByFunctionAndMarker(v:lnum)