vim.vim (544B) [raw]
1 " Custom folding by expression to fold markers and functions 2 3 let b:viml_fold_markers = split(&foldmarker, ',') 4 5 function! VimLFoldByFunctionAndMarker(lnum) abort 6 let l = getline(a:lnum) 7 if l =~ '^\s*function!\? ' 8 return 'a1' 9 elseif l =~ '^\s*endfunction' 10 return 's1' 11 elseif l =~ b:viml_fold_markers[0] 12 return 'a1' 13 elseif l =~ b:viml_fold_markers[1] 14 return 's1' 15 else 16 return '=' 17 endif 18 endfunction 19 20 setlocal foldmethod=expr 21 setlocal foldexpr=VimLFoldByFunctionAndMarker(v:lnum)