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

Re: Folding

Expand Messages
  • Eric Weir
    ... I meant both. I see that neither accomplishes what I wanted, i.e., for the folded indent to display as indented. As it is, it appears to me that the only
    Message 1 of 24 , Jun 2, 2011
    • 0 Attachment
      On Jun 1, 2011, at 10:53 AM, Ben Fritz wrote:

      > On Jun 1, 8:37 am, Eric Weir <eew...@...> wrote:
      >
      >> I understand folds can be indented.
      >
      > How do you mean? You can fold based on existing indent, which will
      > fold all lines having the same indent into a single displayed line,
      > where "line" means a newline-terminated string.
      >
      > Or, if you have a fold, you can use the >> operator to increase the
      > indent of everything inside the fold.

      I meant both. I see that neither accomplishes what I wanted, i.e., for the folded indent to display as indented. As it is, it appears to me that the only way to know a fold is indented is to undent it.

      But having tried that I see that that would not have accomplished what I wanted anyway, i.e., for all text with a certain range of a given line to "disappear under" that line. But I see that there is a way that can be done, by folding the other lines first, then folding on the first line and the lines that have already been folded.

      I just wish I could get rid of the prefix that indicates how many lines there are in the fold. No doubt that is useful to some. To me it is clutter. It just gets in the way. The text of the top level line is sufficient to identify what's in the fold as far as I'm concerned.

      >> Is it possible to get Vim to wrap words to the indent column?
      >
      > Again, what do you mean by wrapping? Usually this means you have a
      > single long line which Vim displays on many lines by "wrapping" the
      > text which goes past the edge of the window. This is accomplished by
      > setting the 'wrap' option and probably 'linebreak' as well so that Vim
      > only wraps at word boundaries.

      I've done that. The options you suggest either don't do what I want, i.e., to display all and screen lines of an indented text, and only those lines as indented; or do things I don't want, e.g., insert hard returns into the text.

      That said, I've come to the conclusion that I don't need to do what I wanted to do, that the method of "folding on folds" will accomplish most of what I wanted.

      >> Is there a way I can get folds to persist across a save and reload?
      >
      > I understand the :mkview command will save manual folds, which
      > the :loadview command will restore. There is probably a plugin to do
      > this for you automatically.

      Sounds like that would do the job. Especially if I could do it on a per file basis, i.e., without specifying filetypes to which it applies or having it apply globally.

      I'll read up on the command, and will probably have more questions after that.

      Thanks for the informative response to my noobie questions.

      ------------------------------------------------------------------------------------------
      Eric Weir
      Decatur, GA USA
      eeweir@...




      --
      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
    • Gary Johnson
      ... I don t like all that clutter in the fold line, either, but I do like to see the number of lines in the fold, so I modified the appearance of the fold line
      Message 2 of 24 , Jun 2, 2011
      • 0 Attachment
        On 2011-06-02, Eric Weir wrote:

        > I just wish I could get rid of the prefix that indicates how many
        > lines there are in the fold. No doubt that is useful to some. To
        > me it is clutter. It just gets in the way. The text of the top
        > level line is sufficient to identify what's in the fold as far as
        > I'm concerned.

        I don't like all that clutter in the fold line, either, but I do
        like to see the number of lines in the fold, so I modified the
        appearance of the fold line with this in my ~/.vimrc.

        set foldtext=MyFoldText()

        " MyFoldText()
        "
        " This is intended to be the same as the default foldtext()
        " function, but without the text of the first line of the fold.
        " See f_foldtext() in eval.c to see how the string is built.
        "
        function! MyFoldText()
        let n = v:foldend - v:foldstart + 1
        let i = indent(v:foldstart)
        let istr = ''
        while i > 0
        let istr = istr . ' '
        let i = i - 1
        endwhile
        return istr . "+-" . v:folddashes . " " . n . " lines "
        endfunction

        You could do something similar to get the appearance you want. I
        wrote it before the repeat() function was available, so it could
        probably be rewritten with five fewer lines today. See

        :help fold-foldtext

        Regards,
        Gary

        --
        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
        ... Ah, so you want to modify what is displayed in place of the folded text. This is certainly possible, using the foldtext option. If you can specify
        Message 3 of 24 , Jun 2, 2011
        • 0 Attachment
          On Jun 2, 8:47 am, Eric Weir <eew...@...> wrote:
          >
          > I meant both. I see that neither accomplishes what I wanted, i.e., for the folded indent to display as indented. As it is, it appears to me that the only way to know a fold is indented is to undent it.
          >
          > [Snip]
          >
          > I just wish I could get rid of the prefix that indicates how many lines there are in the fold. No doubt that is useful to some. To me it is clutter. It just gets in the way. The text of the top level line is sufficient to identify what's in the fold as far as I'm concerned.  
          >

          Ah, so you want to modify what is displayed in place of the folded
          text. This is certainly possible, using the 'foldtext' option.

          If you can specify exactly what you want folded text to look like,
          someone can help you make one. Or you can try your hand yourself.
          There are a couple of examples at :help fold-foldtext and also
          http://vim.wikia.com/wiki/Folding_for_plain_text_files_based_on_indentation
          and http://vim.wikia.com/wiki/Customize_text_for_closed_folds. The
          first link above may be very close to what you are looking for by
          itself.

          The caveat to remember in terms of indenting folded lines is that a
          tab character in the fold text is replaced with a single space, so
          you'll need to do something like this to replace it:

          linetext = substitute(getline(v:foldstart),'^\s\+','\=repeat("
          ",strdisplaywidth(submatch(0)))', '')

          This replaces a sequence of whitespace at the beginning of the line ('^
          \s\+') with a sequence of space characters ( repeat(" " ) of length
          equal to the width of the whitespace sequence as displayed in Vim
          ( strdisplaywidth(submatch(0)) ).

          --
          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
        • sc
          ... i bet this was written before we had the repeat() function sc -- You received this message from the vim_use maillist. Do not top-post! Type your reply
          Message 4 of 24 , Jun 2, 2011
          • 0 Attachment
            On Thursday, June 02, 2011 09:36:07 Gary Johnson wrote:

            > while i > 0
            > let istr = istr . ' '
            > let i = i - 1
            > endwhile

            i bet this was written before we had the repeat() function

            sc

            --
            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
          • Gary Johnson
            ... Yeah. That s why a little farther down the page I also wrote: You could do something similar to get the appearance you want. I wrote it before the
            Message 5 of 24 , Jun 2, 2011
            • 0 Attachment
              On 2011-06-02, sc wrote:
              > On Thursday, June 02, 2011 09:36:07 Gary Johnson wrote:
              >
              > > while i > 0
              > > let istr = istr . ' '
              > > let i = i - 1
              > > endwhile
              >
              > i bet this was written before we had the repeat() function

              Yeah. That's why a little farther down the page I also wrote:

              You could do something similar to get the appearance you want. I
              wrote it before the repeat() function was available, so it could
              probably be rewritten with five fewer lines today.

              Regards,
              Gary

              --
              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
            • Eric Weir
              ... Thanks, Gary. As I mentioned in my original post on this thread, I m not a programmer. I think I understand what this does, but from your description, not
              Message 6 of 24 , Jun 3, 2011
              • 0 Attachment
                On Jun 2, 2011, at 10:36 AM, Gary Johnson wrote:

                > I don't like all that clutter in the fold line, either, but I do
                > like to see the number of lines in the fold, so I modified the
                > appearance of the fold line with this in my ~/.vimrc.
                >
                > set foldtext=MyFoldText()
                >
                > " MyFoldText()
                > "
                > " This is intended to be the same as the default foldtext()
                > " function, but without the text of the first line of the fold.
                > " See f_foldtext() in eval.c to see how the string is built.
                > "
                > function! MyFoldText()
                > let n = v:foldend - v:foldstart + 1
                > let i = indent(v:foldstart)
                > let istr = ''
                > while i > 0
                > let istr = istr . ' '
                > let i = i - 1
                > endwhile
                > return istr . "+-" . v:folddashes . " " . n . " lines "
                > endfunction
                >
                > You could do something similar to get the appearance you want. I
                > wrote it before the repeat() function was available, so it could
                > probably be rewritten with five fewer lines today.

                Thanks, Gary. As I mentioned in my original post on this thread, I'm not a programmer. I think I understand what this does, but from your description, not the code. As I understand it eliminates all text except the number of lines. I want to eliminate the number of lines and keep the text from the first line of the fold. And I have absolutely no idea how to go about revising the code to make it do what I want.

                Thanks again nevertheless.

                Sincerely,
                ------------------------------------------------------------------------------------------
                Eric Weir
                Decatur, GA USA
                eeweir@...




                --
                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
              • Eric Weir
                ... Thanks, Ben. What I would like is that the line displayed by the fold be simply the first screen line of text of the fold. I took a look at the suggestions
                Message 7 of 24 , Jun 3, 2011
                • 0 Attachment
                  On Jun 2, 2011, at 11:02 AM, Ben Fritz wrote:

                  > Ah, so you want to modify what is displayed in place of the folded
                  > text. This is certainly possible, using the 'foldtext' option.
                  >
                  > If you can specify exactly what you want folded text to look like,
                  > someone can help you make one. Or you can try your hand yourself.
                  > There are a couple of examples at :help fold-foldtext and also
                  > http://vim.wikia.com/wiki/Folding_for_plain_text_files_based_on_indentation
                  > and http://vim.wikia.com/wiki/Customize_text_for_closed_folds. The
                  > first link above may be very close to what you are looking for by
                  > itself.

                  Thanks, Ben. What I would like is that the line displayed by the fold be simply the first screen line of text of the fold.

                  I took a look at the suggestions at the links above. While they address folding generally, rather what's displayed by the fold, I found the first especially interesting. I really am not a programmer, however, and at this point at least, couldn't begin trying to implement what's described there.

                  A link provided at the first link http://jfi.uchicago.edu/~tten/for%20geeks/Vim_editor/ provides an alternative based on "reverse indenting" -- I don't understand the rationale for employing "reverse indenting" -- that comes as close as I've seen to what I want, including hierarchical outlining without a plugin or special coding of files, and an uncluttered fold display. Just the first line of the folded text is displayed. Again, however, as close as it seems to what I want, I am again definitely not in a position to take on implementing it at this time.

                  Something somewhere in the reading to which I was led by your response led me to this really good overview of folding on Vim Tips that I think I need to study. http://vim.wikia.com/wiki/Folding#Indent_folding One option discussed there is one that provides for folding based on indents and manual folding that looks similar to a suggestion to which I was led by a response on mac_vim that provides for retention of folds across a save and reload. It' very simple, but for some reason is not working for me exactly as described. [I'm getting error messages and recently saved folds are opening with fewer lines folded than were saved.]

                  I know I'm being vague. I'm getting clearer as I pursue the suggestions I'm getting, at least about what I want. Definitely not very clear yet how to get it. But I am not a programmer. This is not something I need to do. It's something I want to do. I accept that it's going to take time, and that a fair bit of learning will be involved.

                  Thanks again,
                  ------------------------------------------------------------------------------------------
                  Eric Weir
                  Decatur, GA USA
                  eeweir@...




                  --
                  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
                • Gary Johnson
                  ... The example at the top of :help fold-foldtext does that. (The line beginning :set foldtext=v:folddashes... ) Try that and see if it does what you
                  Message 8 of 24 , Jun 4, 2011
                  • 0 Attachment
                    On 2011-06-03, Eric Weir wrote:
                    > On Jun 2, 2011, at 10:36 AM, Gary Johnson wrote:
                    >
                    > > I don't like all that clutter in the fold line, either, but I do
                    > > like to see the number of lines in the fold, so I modified the
                    > > appearance of the fold line with this in my ~/.vimrc.
                    > >
                    > > set foldtext=MyFoldText()
                    > >
                    > > " MyFoldText()
                    ...
                    > > You could do something similar to get the appearance you want. I
                    > > wrote it before the repeat() function was available, so it could
                    > > probably be rewritten with five fewer lines today.
                    >
                    > Thanks, Gary. As I mentioned in my original post on this thread,
                    > I'm not a programmer. I think I understand what this does, but
                    > from your description, not the code. As I understand it eliminates
                    > all text except the number of lines. I want to eliminate the
                    > number of lines and keep the text from the first line of the fold.
                    > And I have absolutely no idea how to go about revising the code to
                    > make it do what I want.

                    The example at the top of ":help fold-foldtext" does that. (The
                    line beginning ":set foldtext=v:folddashes...") Try that and see if
                    it does what you want.

                    Regards,
                    Gary

                    --
                    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
                  • Eric Weir
                    ... Thanks, Gary. Comes close. I still get a report of the number of lines in the fold. I just plunked the line as is from the help screen into my .vimrc, but
                    Message 9 of 24 , Jun 4, 2011
                    • 0 Attachment
                      On Jun 4, 2011, at 3:27 AM, Gary Johnson wrote:

                      >> On 2011-06-03, Eric Weir wrote:
                      >>
                      >> I want to eliminate the
                      >> number of lines and keep the text from the first line of the fold.
                      >> And I have absolutely no idea how to go about revising the code to
                      >> make it do what I want.
                      >
                      > The example at the top of ":help fold-foldtext" does that. (The
                      > line beginning ":set foldtext=v:folddashes...") Try that and see if
                      > it does what you want.

                      Thanks, Gary. Comes close. I still get a report of the number of lines in the fold.

                      I just plunked the line as is from the help screen into my .vimrc, but I can't read it, and don't see how to modify it to get rid of the number of lines report.

                      Is there a way to do that?

                      ------------------------------------------------------------------------------------------
                      Eric Weir
                      Decatur, GA USA
                      eeweir@...




                      --
                      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
                    • Gary Johnson
                      ... That line, ... does not include the number of lines in the fold, so either it is not being executed in your ~/.vimrc or the option is being set to some
                      Message 10 of 24 , Jun 4, 2011
                      • 0 Attachment
                        On 2011-06-04, Eric Weir wrote:
                        > On Jun 4, 2011, at 3:27 AM, Gary Johnson wrote:
                        >
                        > >> On 2011-06-03, Eric Weir wrote:
                        > >>
                        > >> I want to eliminate the
                        > >> number of lines and keep the text from the first line of the fold.
                        > >> And I have absolutely no idea how to go about revising the code to
                        > >> make it do what I want.
                        > >
                        > > The example at the top of ":help fold-foldtext" does that. (The
                        > > line beginning ":set foldtext=v:folddashes...") Try that and see if
                        > > it does what you want.
                        >
                        > Thanks, Gary. Comes close. I still get a report of the number of
                        > lines in the fold.
                        >
                        > I just plunked the line as is from the help screen into my .vimrc,
                        > but I can't read it, and don't see how to modify it to get rid of
                        > the number of lines report.
                        >
                        > Is there a way to do that?

                        That line,

                        :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')

                        does not include the number of lines in the fold, so either it is
                        not being executed in your ~/.vimrc or the option is being set
                        to some other value somewhere after your ~/.vimrc is read. Execute

                        :verbose foldtext?

                        and see what it reports. It will show you the current value of the
                        'foldtext' option and where it was last set.

                        Regards,
                        Gary

                        --
                        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
                      • Eric Weir
                        ... It does seem to be being executed. What s displayed is definitely different. Minus the line number report -- which of course I can live with till I learn
                        Message 11 of 24 , Jun 5, 2011
                        • 0 Attachment
                          On Jun 5, 2011, at 2:38 AM, Gary Johnson wrote:

                          > That line,
                          >
                          > :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')
                          >
                          > does not include the number of lines in the fold, so either it is
                          > not being executed in your ~/.vimrc or the option is being set
                          > to some other value somewhere after your ~/.vimrc is read.

                          It does seem to be being executed. What's displayed is definitely different. Minus the line number report -- which of course I can live with till I learn how to get rid of it -- it's exactly what I want.

                          > Execute
                          >
                          > :verbose foldtext?
                          >
                          > and see what it reports. It will show you the current value of the
                          > 'foldtext' option and where it was last set.

                          Weird. When I execute that command I get an error message: "W492: Not an editor command: verbose foldtext?" [I also tried it without the "?".]

                          I've checked help on :verbose, but it didn't help me understand why I'm getting this message. .

                          Thanks again,
                          ------------------------------------------------------------------------------------------
                          Eric Weir
                          Decatur, GA USA
                          eeweir@...




                          --
                          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
                        • Tony Mechelynck
                          ... You should have typed ... -- :foldtext? by itself is indeed not an editor command -- one word slipped off Gary s typing. ... HTH, Tony. -- An exotic
                          Message 12 of 24 , Jun 5, 2011
                          • 0 Attachment
                            On 05/06/11 16:28, Eric Weir wrote:
                            >
                            > On Jun 5, 2011, at 2:38 AM, Gary Johnson wrote:
                            >
                            >> That line,
                            >>
                            >> :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')
                            >>
                            >> does not include the number of lines in the fold, so either it is
                            >> not being executed in your ~/.vimrc or the option is being set
                            >> to some other value somewhere after your ~/.vimrc is read.
                            >
                            > It does seem to be being executed. What's displayed is definitely different. Minus the line number report -- which of course I can live with till I learn how to get rid of it -- it's exactly what I want.
                            >
                            >> Execute
                            >>
                            >> :verbose foldtext?
                            >>
                            >> and see what it reports. It will show you the current value of the
                            >> 'foldtext' option and where it was last set.
                            >
                            > Weird. When I execute that command I get an error message: "W492: Not an editor command: verbose foldtext?" [I also tried it without the "?".]
                            >
                            > I've checked help on :verbose, but it didn't help me understand why I'm getting this message. .

                            You should have typed

                            :verbose set foldtext?

                            -- :foldtext? by itself is indeed not an editor command -- one word
                            slipped off Gary's typing.

                            >
                            > Thanks again,
                            > ------------------------------------------------------------------------------------------
                            > Eric Weir
                            > Decatur, GA USA
                            > eeweir@...
                            >
                            >
                            >
                            >

                            HTH,
                            Tony.
                            --
                            An exotic journey in downtown Newark is in your future.

                            --
                            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
                          • Eric Weir
                            ... Thanks, Tony. ... Eric Weir Decatur, GA USA eeweir@bellsouth.net -- You received this message from the vim_use maillist. Do not top-post! Type your
                            Message 13 of 24 , Jun 5, 2011
                            • 0 Attachment
                              On Jun 5, 2011, at 10:51 AM, Tony Mechelynck wrote:

                              > On 05/06/11 16:28, Eric Weir wrote:
                              >>
                              >>> On Jun 5, 2011, at 2:38 AM, Gary Johnson wrote:
                              >>>
                              >>> Execute
                              >>>
                              >>> :verbose foldtext?
                              >>>
                              >>> and see what it reports. It will show you the current value of the
                              >>> 'foldtext' option and where it was last set.
                              >>
                              >> Weird. When I execute that command I get an error message: "W492: Not an editor command: verbose foldtext?" [I also tried it without the "?".]
                              >>
                              >> I've checked help on :verbose, but it didn't help me understand why I'm getting this message. .
                              >
                              > You should have typed
                              >
                              > :verbose set foldtext?

                              Thanks, Tony.

                              ------------------------------------------------------------------------------------------
                              Eric Weir
                              Decatur, GA USA
                              eeweir@...




                              --
                              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
                            • Eric Weir
                              ... The report was that the line I inserted was the only one setting foldtext:
                              Message 14 of 24 , Jun 5, 2011
                              • 0 Attachment

                                On Jun 5, 2011, at 2:38 AM, Gary Johnson wrote:

                                That line,

                                   :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')

                                does not include the number of lines in the fold, so either it is
                                not being executed in your ~/.vimrc or the option is being set
                                to some other value somewhere after your ~/.vimrc is read.  Execute

                                   :verbose foldtext?

                                and see what it reports.  It will show you the current value of the
                                'foldtext' option and where it was last set.

                                The report was that the line I inserted was the only one setting foldtext: 

                                foldtext=v:folddashes.substitute(getline(v:foldstart),'/\*\|\*/\|{{{\d\=','','g')
                                        Last set from ~/.vimrc  

                                Is there something other than foldtext that would affect display of the number of lines?

                                Thanks,
                                ------------------------------------------------------------------------------------------
                                Eric Weir
                                Decatur, GA  USA
                                eeweir@...




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