How to open all folds containing a search pattern at the same time?

I have a file consisting of about a hundred paragraphs, each of which is folded according to the third example in the help section of fold-expr: help, which rolls back paragraphs separated by blank lines:

set foldmethod=expr set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1 

Suppose I run a search pattern like

 /Item 014 

This pattern can be found in 7 different folds.

I know that I can just press "n" 6 times to open all the folds associated with the search in sequence.

But I would like to have 7 cards in one move to get a quick overview.

I tried a macro

 qu nq 

then

 /Item 014 100@u 

but failed.

How should I proceed?

+4
source share
1 answer

After performing a search for /Item 014 you can use the following command to open all the folds containing the template:

 :g//foldopen 

This exploits the fact that the command :g reuses the last search pattern when it is left blank. Thus, the Ex :foldopen is executed on all matching lines: it opens a fold on the current line.

+13
source

Source: https://habr.com/ru/post/1502204/


All Articles