Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

folding

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 ?

like image 231
ThG Avatar asked Dec 07 '22 05:12

ThG


1 Answers

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.

like image 71
glts Avatar answered Apr 27 '23 20:04

glts