Wednesday, March 18, 2015

Re: 3zo should open fold upto depth of 3

On 3/18/15, Paul <Paul.Domaskis@gmail.com> wrote:
> esquifit <esquifit <at> googlemail.com> writes:
> |On Tuesday, March 17, 2015 at 10:08:44 PM UTC+2, Paul wrote:
> |> According to the documentation for folds, the command 3zo should
> |> open folds to a depth of 3. When I move the cursor to a top-level
> |> fold and enter 3zo, it's as if I only entered zo, i.e. only the top
> |> level fold opens. I have foldmethod=indent. There are in fact
> |> subfolds at levels 2 and 3 within the top level fold.
> |>
> |> Can anyone corroborate this behaviour? Am I misinterpretting the
> |> help? How can I get the effect I seek, i.e., open a fold by a
> |> certain depth?
> |
> | This is what I observe:
> |
> | It will behave as described in the help if the cursor were inside
> | the folded region at the time the folded was closed. If you're
> | moving from outside the fold and put the cursor over the closed
> | fold, this will correspond to the first line of the folded region.
> | Normally, this line belongs only to the topmost fold level, so
> | making 3zo will be no different from zo.
> |
> | Example:
> | * Place the cursor on a 3-deep nested fold and type 3zc. Vim will
> | fold three levels upwards. Your cursor is still inside the folder
> | region.
> |
> | * Do 3zo and Vim will open up the fold up to level 3.
> | * Now do 3zc and move the cursor outside the closed fold.
> |
> | * Place the cursor again over the closed fold and type 3zo. Only one
> | level will be unfolded, because the cursor is on the first line of
> | the region, which has no deeper fold-level than 1.
>
> Ah, so it limits the opening of a nested fold down *toward* the
> location of the cursor rather than down *from* the cursor. I wonder
> if there is a way to limit the opening of folds down from the cursor?
> The normal-mode command zr for opening of folds is global in scope
> (meaning throughout the current window, not throughout all windows &
> buffers).
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


The docs for zc and zo are a bit misleading. zc anc zo operate only on
folds that *contain* the cursor line. This includes folds that start on
the cursor line, but not subfolds that start below the cursor.
I recommend to enable 'foldcolumn' when figuring out how folding works,
it shows exactly where the folds are. Consider the following test file:

vim: fdm=marker fdc=6
aa{{{ bb{{{ cc{{{
{{{
dd
}}}
cc}}}
bb}}}
aa}}}

With cursor on first aa line and everything folded (zM), 3 or more zo
will open the first three folds, but not nested fold dd.
To open/close nested folds as well, one can use zO, zC, zA. Since zC
also closes folds that start above the cursor and thus can hide the
cursor, follow it with zv.

Best regards,
Vlad

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: