Loading ...
Sorry, an error occurred while loading the content.
 

Re: Folding recursively/levels

Expand Messages
  • Ben Fritz
    ... I think you misunderstand folds under the cursor . With the cursor on the A node, folds on B and C nodes are not under the cursor at all. Therefore zC
    Message 1 of 3 , Sep 28, 2011
      On Sep 28, 2:28 am, philipx <goo...@...> wrote:
      > Hi.
      >
      > I'm having troubles understanding folding, in particular the recursive
      > folding.
      > I expect that if I fold a multi-level document (e.g. XML) with "zC" -
      > "Close all folds under the cursor recursively", and then I execute
      > "zo" on the fold, it would "Open one fold under the cursor", meaning
      > that it keeps lower levels folded.
      > Say you have this xml document (fdm=syntax,
      > g:xml_syntax_folding=1,foldlevelstart=99).
      > A
      >   B
      >     C
      >     C
      >   B
      >     C...
      >   B
      >     C...
      >
      > Execute zC on the A node:
      > --- xx lines: <A>------
      > Now executing zo on that line, I would expect to see the following:
      > A
      >   -- xx lines: <B>-----
      >   -- xx lines: <B>-----
      >   -- xx lines: <B>-----
      >
      > Instead the whole tree opens up, which is what I would expect to
      > happen if I used zO not zo.
      >
      > Are my expectations wrong? Is there a way to achieve this incremental
      > unfolding I am looking for?
      >
      > Thanks.

      I think you misunderstand "folds under the cursor".

      With the cursor on the A node, folds on B and C nodes are not under
      the cursor at all. Therefore zC does not close them. Note the text
      of :he zC, which says, "Folds that don't contain the cursor line are
      unchanged."

      But with your cursor on the C node, zC will close the B node above it
      and the A node above that.

      What you probably want is to adjust the fold level with zm/zr/zM/zR.
      You could also use :foldclose! with a range (where a range could be
      determined by a complicated regex or a visual selection even).

      I also just learned about zC in visual mode, from reading the help.
      Another solution would be to visually select all the lines which you
      wish to close all folds in, and use zC on the visual selection. With
      the % command and the matchit plugin, this should only be a few extra
      keystrokes (e.g. V%zC instead of just zC). This should do about the
      same thing as :foldclose! on a visual selection but with fewer
      keystrokes.

      --
      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
    Your message has been successfully submitted and would be delivered to recipients shortly.