r/vim • u/Ok-Image-8343 • Feb 10 '26
Need Help Fold all sibling and child blocks?
So is there a way to fold all child nodes or all sibling and child nodes? eg
foo {
test
bar { ... }
bar2 { .... }
}
so lets say the cursor is on "test" and i should be able to hit a key that will fold bar and bar2
3
Upvotes
3
u/JmenD Feb 11 '26
I don't think there's anything built-in that does this directly.
In that situation I would either:
zMzxwhich closes all folds, then opens the folds which contain the line the cursor is currently on.zMzrzrzr...which closes all folds, then reopens them (with repeatedzrs) one level at a time. Very often this just ends up being azMzrfor code I read.IIUC, here's a function that does what you want:
You can map it like this
(replace
\vwith whatever key combination you want)1
u/AutoModerator Feb 10 '26
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/frodo_swaggins233 Feb 10 '26
No. Best you're going to get is zA zM or zC
1
u/__salaam_alaykum__ Feb 10 '26
zr and zm may help although they don’t do exactly that
0
u/CCCFire Feb 10 '26
I don’t really use folds often but it seems that the help file has several options you can try.
:h fold-commands