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

Overcoming unintended folding [Was: A mile of dashes added to foldtext]

Expand Messages
  • Erik Christiansen
    ... That is clever and simple to implement. (And revealing of better ways to think about Vim. :-) ... Chuckle. Yes, the comment is needed. ... Yes, that was
    Message 1 of 7 , Aug 1, 2011
    • 0 Attachment
      On 01.08.11 08:29, Benjamin R. Haskell wrote:
      > On Mon, 1 Aug 2011, Erik Christiansen wrote:
      > >
      > >It has also become clear that I'll have to constrain the folding
      > >with some "au BufNewFile,BufRead", because .vimrc is only partly
      > >displayed, apparently due to the foldtext regex being interpreted
      > >as the start of a fold.
      >
      > Three ways to work around this portion of the problem:
      >
      > 1. Limit the damage by placing a closing foldmarker in a comment:
      >
      > e.g.
      >
      > set foldtext=substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g') " }}}
      >

      That is clever and simple to implement. (And revealing of better ways to
      think about Vim. :-)

      > 2. Replace the three-open-brace portion of the regular expression
      > with something equivalent:
      >
      > e.g.:
      >
      > Change '{{{' into '[{]{{' " [ed. preventing the fold on this line]: }}}

      Chuckle. Yes, the comment is needed.

      >
      > 3. Use setlocal instead of set to set up foldmethod=marker.
      >
      > If you set fdm=manual, then folding is manual globally. Then in
      > specific filetypes you can enable fdm=marker.
      >
      > E.g. I use:
      >
      > " in .vimrc:
      > set fdm=manual
      > au Filetype php setl fdm=marker

      Yes, that was the only one I'd come up with, but had not considered the
      need for setlocal. (And just triggering the au on filenames, because my
      various info files don't have a different filetype. Also, I'll possibly
      want slightly different foldtext on some of the others, when I get to
      them.)

      Many thanks for the nifty solutions. This is enjoyably educational, as
      well as making Vim more powerful here.

      Erik

      --
      Meskimen's Law:
      There's never time to do it right, but always time to do it over.

      --
      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
    • Ben Fritz
      ... Most operations done on a closed fold will act on all lines within the fold. For example, if you have a big 1234-line fold, close the fold and press dd
      Message 2 of 7 , Aug 1, 2011
      • 0 Attachment
        On Aug 1, 6:40 am, Erik Christiansen <dva...@...> wrote:
        > Vim's help has a number of fold-related commands, but I'm having trouble
        > finding a command to delete a fold, for pasting elsewhere. So not zd,
        >         ---------------------------
        > which just negates the fold. (The perspective provided by folding
        > reveals that some folds need to be moved.)
        >
        > Perhaps there is a "to end of fold" motion, to use with d, even though I
        > don't see one in motion.txt.

        Most operations done on a closed fold will act on all lines within the
        fold. For example, if you have a big 1234-line fold, close the fold
        and press "dd" on the foldtext as if you were deleting just one line.
        The entire folded text will be deleted, ready to put elsewhere.

        If you need more fine-grained control, you're also right to think of a
        "to end of fold" motion. ]z does exactly this, if the cursor is inside
        an open fold. [z similarly goes to the start of the open fold. You can
        also move between folds with zj/zk.

        --
        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
      • Erik Christiansen
        ... Oooh, that is just cooler than menthol. :-)) ... Ah, yes, I should have looked in :h folds as well as motion. The folding feature is a delight, with
        Message 3 of 7 , Aug 2, 2011
        • 0 Attachment
          On 01.08.11 13:18, Ben Fritz wrote:
          > On Aug 1, 6:40 am, Erik Christiansen <dva...@...> wrote:
          > > Perhaps there is a "to end of fold" motion, to use with d, even though I
          > > don't see one in motion.txt.
          >
          > Most operations done on a closed fold will act on all lines within the
          > fold. For example, if you have a big 1234-line fold, close the fold
          > and press "dd" on the foldtext as if you were deleting just one line.
          > The entire folded text will be deleted, ready to put elsewhere.

          Oooh, that is just cooler than menthol. :-))

          > If you need more fine-grained control, you're also right to think of a
          > "to end of fold" motion. ]z does exactly this, if the cursor is inside
          > an open fold. [z similarly goes to the start of the open fold. You can
          > also move between folds with zj/zk.

          Ah, yes, I should have looked in ":h folds" as well as motion.

          The folding feature is a delight, with those motions, and the power of
          "dd". Very, _very_ nice. :-))

          Now that we have it, I wouldn't give it up for the weight of emacs in
          pizza.

          Thank you for leading this horse to water.

          Erik

          --
          I have yet to see any problem, however complicated, which, when you
          looked at it in the right way, did not become still more complicated.
          - Poul Anderson

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