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

  1. Close the parent fold
  2. Select closed fold and next line
  3. :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 children
  • zm: Increases the foldlevel by one, i.e. closes the innermost level of folds that are not yet folded

The opposite commands are:

  • zR: All folds are open
  • zr: Decreases the foldlevel by one

Note: 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.

Fold only current children recursive

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:

  1. go to a line in father folding level
  2. Press (in normal mode) zxzc. Or remap it: nnoremap zxc zxzc

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Unfold only current children recursive

Btw: to do the opposite, open recursive all children: zczA

Credits: https://vi.stackexchange.com/a/16046/29452

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Un-/Fold only selected recursive

Or to open/close a desired range of folds recursive:

  1. Select the range visually.
  2. :foldo (as previous link) or :foldc (as @majkinetor answer).

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.

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