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.
With the following in your vimrc, you can toggle folds open/closed by pressing F9. In addition, if you have :set foldmethod=manual , you can visually select some lines, then press F9 to create a fold. Here is an alternative procedure: In normal mode, press Space to toggle the current fold open/closed.
Vim uses the same movement commands to define folds. Folding also works in visual mode. If you enter visual mode using v or V , then select a few lines of text using the movement keys, and type zf , Vim will create a fold comprising those lines. Another option is to specify a range in command mode.
Code or text folding, or less commonly holophrasting, is a feature of some graphical user interfaces that allows the user to selectively hide ("fold") or display ("unfold") parts of a document. This allows the user to manage large amounts of text while viewing only those subsections that are currently of interest.
The problem is that when you close Vim, your artfully folded code returns to its unfolded state. The solution is quite simple - when you are ready to save your folds run the :mkview command. This will save your folds in the current buffer to your viewdir ( :h viewdir ) depending on your environment.
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
.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With