Question

I have a file consisting in about a hundred paragraphs, each one being folded according to the third example under the :help fold-expr section, which makes a fold out of paragraphs separated by blank lines :

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

Suppose I launch a search pattern, e.g.

/Item 014

This pattern may be found in 7 of the different folds.

I know I could just press "n" 6 times to open successively all the folds concerned by the search.

But I would like to have the 7 folds opened in one move, in order to have a quick overview.

I tried a macro

qu n q

then

/Item 014
100@u

but failed.

How should I proceed ?

Was it helpful?

Solution

After having performed your search for /Item 014, you can use the following command to open all folds containing the pattern:

:g//foldopen

This takes advantage of the fact that the :g command reuses the last search pattern when left empty. The Ex command :foldopen is thus executed on all matching lines: it opens the fold on the current line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top