6 years ago
How to search a pattern and fold the matching lines
Hi , I want to fold set of lines after search as follows, > The mouse can also be used to open and close folds by following steps: Click on a '+' to open the closed fold at this row. Click on any other non-blank character to close the open fold at this row > I want to search click and collapse all matching lines. > The mouse can also be used to open and close folds by followingsteps: +-- > There is a method to collapse the patterns which are not matching in vim , after searching a pattern we can collapse non matching patterns by "\z" key . ``` nnoremap \z :setlocal foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\\|\\|(getline(v:lnum+1)=~@/)?1:2 foldmethod=expr foldlevel=0 foldcolumn=2<CR> ``` Is there any option to do the opposite? Just find a pattern and collapse?