danvk
danvk

Reputation: 16935

Open all folds matching a pattern in vim

I'm using vim's syntax folding to look at a large GeoJSON file:

Collapsed GeoJSON file

If I type /properties<ENTER>, it unfolds everything on the path down to the first Feature's properties:

Expanded properties

Now if I hit n a bunch of times, it will go through the file and expand all the properties fields.

I'd like to do this in a single command. I've tried :g/"properties": {/foldopen but this only opens the path to the properties fields, not the properties fields themselves:

Mostly expanded, need one more level

How can I get this :g command to expand the properties fields, too?

Upvotes: 1

Views: 117

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172570

The :foldopen just opens a single level of folding. Now if you use :foldopen! (with !), it will open all folds. But I think this still isn't what you want, because if you start with everything folded into one big fold, each and every fold will be opened (so you could just do zR). What you want is opening all folds to be able to see the current (searched for) line; zv does that:

:g/"properties": {/normal! zv

If you want all subfolds opened as well, use normal! zvzO instead.

Upvotes: 2

Related Questions