- Close the parent fold
- Select closed fold and next line
:foldc!
- closes all folds in range`<,`>
(read:h foldc
)
You can obviously map that sequence.
Question
I know how to open all folds under cursor with zO
.
But how to do reverse?
I want something like za
does, but also with recursivity.
PS. I know there is zC
, but it closes all parent folds in relation to current line and I want to close children.
No correct solution
OTHER TIPS
:foldc!
- closes all folds in range `<,`>
(read :h foldc
)You can obviously map that sequence.
I did not actually find an exact answer to this question, but a few commands than could be a workaround in some cases are:
zM
: Closes recursively the root folds and all their childrenzm
: Increases the foldlevel by one, i.e. closes the innermost level of folds that are not yet foldedThe opposite commands are:
zR
: All folds are openzr
: Decreases the foldlevel by oneNote: the question deals with only current children. I.e to close/open till current fold level, and NOT all the way as zC
, zO
, zA
, zM
, zR
.
zx folds: Undo manually opened and closed folds: re-apply 'foldlevel', then do "zv": View cursor line. Also forces recomputing folds. This is useful when using 'foldexpr' and the buffer is changed in a way that results in folds not to be updated properly.
zc close folded text
I think you want to combine both:
zxzc
. Or remap it: nnoremap zxc zxzc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Btw:
to do the opposite, open recursive all children: zczA
Credits: https://vi.stackexchange.com/a/16046/29452
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Or to open/close a desired range of folds recursive:
Tips to select the range visually:
]z jump to end of current open fold.
[z jump to beginning of current open fold.
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
To jump through closed folds in Vim: https://stackoverflow.com/a/9407015/9391770 (I did not test it yet)
I had this need for a long time too, and what I found out as the closest solution was using zM
to close all folds recursively and then zv
to reopen the line at cursor previous position (before closing folds). Maybe it helps.
Regards.