searchfold.vim (425B)
1 " Search folding (after any regular search, this folds all non-matched lines) 2 function! searchfold#Toggle() abort 3 if exists('b:search_folded') && b:search_folded 4 setlocal foldexpr< foldmethod< foldenable< foldlevel< 5 let b:search_folded = 0 6 else 7 setlocal foldexpr=getline(v:lnum)!~@/ 8 setlocal foldmethod=expr 9 setlocal foldenable 10 setlocal foldlevel=0 11 let b:search_folded = 1 12 endif 13 endfunction