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

Moving a fold? [Was: A mile of dashes added to foldtext]

Expand Messages
  • Erik Christiansen
    ... Paul, you re a wizard. :-) Many thanks for that magical fix! Now I can settle down to examine how useful folding is, but even while only experimenting,
    Message 1 of 7 , Aug 1 4:40 AM
    • 0 Attachment
      On 01.08.11 10:38, Paul wrote:
      > On Mon, Aug 01, 2011 at 06:15:38PM +1000, Erik Christiansen wrote:
      > >But how to remove the extra "--------- ... ------------------" hoo-haa?
      >
      > Try setting 'fold:' in fillchars, eg. set fillchars="fold: "


      Paul, you're a wizard. :-)
      Many thanks for that magical fix!

      Now I can settle down to examine how useful folding is, but even while
      only experimenting, it's a marvel.

      The new difficulty:
      -------------------
      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.

      Folding is already looking good, with the size of each fold visible, but
      secondary, and in pages rather than lines:

      GCC:---------------------- G++ ---------------------------COMPILER: 14 P
      ...
      VIM:--------------------------------------------------------------- 17 P

      (Thanks to Gary Johnson for fold line count arithmetic, in an older post.)

      My right justification is crude:

      let n = v:foldend - v:foldstart + 1
      let s = " "
      let p = n/60 " Lines per page.
      if p > 9
      let s = ""
      endif
      return sub . s . p . " P"

      and will fail if a fold runs to more than 99 pages, but it will do for a
      first attempt at vim scripting.

      Erik

      --
      The poetry of heroism appeals irresistibly to those who don't go to a
      war, and even more so to those whom the war is making enormously wealthy.
      - Celine

      --
      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
    • Benjamin R. Haskell
      ... 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
      Message 2 of 7 , Aug 1 5:29 AM
      • 0 Attachment
        On Mon, 1 Aug 2011, Erik Christiansen wrote:

        > set foldtext=substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')
        > [}}}]
        >
        > [...]
        >
        > let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
        > [}}}]
        >
        > [...]
        >
        > 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') " }}}


        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]: }}}


        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

        --
        Best,
        Ben

        --
        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
        ... 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 3 of 7 , Aug 1 6:21 AM
        • 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 4 of 7 , Aug 1 1:18 PM
          • 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 5 of 7 , Aug 2 12:54 AM
            • 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.