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

Text wrapping / reflowing - two questions.

Expand Messages
  • cga2000
    ... Say, I do the following: 1. I enter insert mode 2. I start to type the following introductory text: I am writing this short email message to ask the
    Message 1 of 11 , Apr 30, 2006
    • 0 Attachment
      When writing email messages I use the following settings:

      :set wrap
      :set textwidth=72

      Say, I do the following:

      1. I enter insert mode

      2. I start to type the following introductory text:

      I am writing this short email message to ask the friendly and
      highly competent folks at vim@... for some help regarding
      the text wrapping feature of Vim... As I was writing an email
      message last night, I ran in to the following problem:

      3. So I start typing:

      I am writing this short email message to ask the friendly folks at
      vim@... for some help regarding the text wrapping feature

      4. I realize at this point that I left out the "highly competent" bit
      so I escape back to normal mode and move the cursor back to the "f"
      of "folks", hit 'i' to switch back to insert mode, type the missing
      text and obtain the following:

      I am writing this short email message to ask the friendly and highly
      competent folks at
      vim@... for some help regarding the text wrapping feature

      5. The first line was correctly "re-wrapped" to accommodate the
      additional text, with "competent folks at" moved to the second line
      but now the rest of my original entry has been moved to a third line
      (vim@... for some help .. etc.)

      6. At this point I escape back to normal mode and hit 'J' to join line
      2-3 and obtain the following:

      I am writing this short email message to ask the friendly and highly
      competent folks at vim@... for some help regarding the text wrapping feature

      7. So I hit 'A' to append the rest of my text to line 2:

      I am writing this short email message to ask the friendly and highly
      competent folks at vim@... for some help regarding the text wrapping feature of Vim... As I was writing an email message last night I ran into the following problem:

      8. In other words and in case the last line above is either truncated or
      rewrapped on your mail reader.. once you have decided to join two
      lines into one long (> textwidth) line, vim quite logically lets you
      append as much text as you wish to that line.

      9. So far the way I handle this is that after J-oining my two lines as
      described above, I move the cursor to the first space before col.72, hit
      'i' and manually insert a carriage return to move the excess text to
      the following line:

      I am writing this short email message to ask the friendly and highly
      competent folks at vim@... for some help regarding the text
      wrapping feature

      Now, after doing the above a number of times I began to think there must
      be a better way to handle this type of situation:

      1. When I end up with (4) above, is there a better strategy than using
      'J' to join line #2 and line #3 .. something that would take me
      directly from (4) to (9) .. hit 'A' and since the cursor would now
      be to the left of col. 72, continue entering my text and benefit
      from the wrap feature automatically?

      2. More generally, is there a command - or sequence of commands - that
      would let me reformat a paragraph to take care of any line that goes
      beyond the limit set via the textwidth option?

      Thanks,

      cga
    • Gary Johnson
      On 2006-05-01, cga2000 wrote: [...] ... Yep. See ... You can easily reformat the paragraph the cursor is currently in by typing this
      Message 2 of 11 , Apr 30, 2006
      • 0 Attachment
        On 2006-05-01, cga2000 <cga2000@...> wrote:

        [...]

        > Now, after doing the above a number of times I began to think there must
        > be a better way to handle this type of situation:
        >
        > 1. When I end up with (4) above, is there a better strategy than using
        > 'J' to join line #2 and line #3 .. something that would take me
        > directly from (4) to (9) .. hit 'A' and since the cursor would now
        > be to the left of col. 72, continue entering my text and benefit
        > from the wrap feature automatically?

        Yep. See

        :help gq
        :help 25.1

        You can easily reformat the paragraph the cursor is currently in by
        typing this in normal mode:

        gqip

        > 2. More generally, is there a command - or sequence of commands - that
        > would let me reformat a paragraph to take care of any line that goes
        > beyond the limit set via the textwidth option?

        There are two approaches to this: manual and automatic. I
        mentioned the manual technique above. You can also add the 'a' and
        'w' flags to 'formatoptions' and have vim automatically reflow your
        text as you type.

        set fo+=aw

        As nice as this sounds, it has its limitations and can sometimes be
        really infuriating. It works well enough that I have my mail.vim
        plugin enable it, but I also have a command to disable it when it
        gets in the way.

        HTH,
        Gary

        --
        Gary Johnson | Agilent Technologies
        garyjohn@... | Wireless Division
        | Spokane, Washington, USA
      • Eric Arnold
        Do you have these set? setlocal formatoptions+=bcroqan2t better without w setlocal linebreak
        Message 3 of 11 , Apr 30, 2006
        • 0 Attachment
          Do you have these set?

          setlocal formatoptions+=bcroqan2t " better without w
          setlocal linebreak



          On 4/30/06, cga2000 <cga2000@...> wrote:
          > When writing email messages I use the following settings:
          >
          > :set wrap
          > :set textwidth=72
          >
          > Say, I do the following:
          >
          > 1. I enter insert mode
          >
          > 2. I start to type the following introductory text:
          >
          > I am writing this short email message to ask the friendly and
          > highly competent folks at vim@... for some help regarding
          > the text wrapping feature of Vim... As I was writing an email
          > message last night, I ran in to the following problem:
          >
          > 3. So I start typing:
          >
          > I am writing this short email message to ask the friendly folks at
          > vim@... for some help regarding the text wrapping feature
          >
          > 4. I realize at this point that I left out the "highly competent" bit
          > so I escape back to normal mode and move the cursor back to the "f"
          > of "folks", hit 'i' to switch back to insert mode, type the missing
          > text and obtain the following:
          >
          > I am writing this short email message to ask the friendly and highly
          > competent folks at
          > vim@... for some help regarding the text wrapping feature
          >
          > 5. The first line was correctly "re-wrapped" to accommodate the
          > additional text, with "competent folks at" moved to the second line
          > but now the rest of my original entry has been moved to a third line
          > (vim@... for some help .. etc.)
          >
          > 6. At this point I escape back to normal mode and hit 'J' to join line
          > 2-3 and obtain the following:
          >
          > I am writing this short email message to ask the friendly and highly
          > competent folks at vim@... for some help regarding the text wrapping feature
          >
          > 7. So I hit 'A' to append the rest of my text to line 2:
          >
          > I am writing this short email message to ask the friendly and highly
          > competent folks at vim@... for some help regarding the text wrapping feature of Vim... As I was writing an email message last night I ran into the following problem:
          >
          > 8. In other words and in case the last line above is either truncated or
          > rewrapped on your mail reader.. once you have decided to join two
          > lines into one long (> textwidth) line, vim quite logically lets you
          > append as much text as you wish to that line.
          >
          > 9. So far the way I handle this is that after J-oining my two lines as
          > described above, I move the cursor to the first space before col.72, hit
          > 'i' and manually insert a carriage return to move the excess text to
          > the following line:
          >
          > I am writing this short email message to ask the friendly and highly
          > competent folks at vim@... for some help regarding the text
          > wrapping feature
          >
          > Now, after doing the above a number of times I began to think there must
          > be a better way to handle this type of situation:
          >
          > 1. When I end up with (4) above, is there a better strategy than using
          > 'J' to join line #2 and line #3 .. something that would take me
          > directly from (4) to (9) .. hit 'A' and since the cursor would now
          > be to the left of col. 72, continue entering my text and benefit
          > from the wrap feature automatically?
          >
          > 2. More generally, is there a command - or sequence of commands - that
          > would let me reformat a paragraph to take care of any line that goes
          > beyond the limit set via the textwidth option?
          >
          > Thanks,
          >
          > cga
          >
        • cga2000
          ... bingo..!! tried this very rapidly and works great - c. 2:45 AM, so I ll have to dig into this - and read the doc - tomorrow.. later today, I mean.. ... You
          Message 4 of 11 , Apr 30, 2006
          • 0 Attachment
            Thus spake Gary Johnson on Sun, Apr 30, 2006 at 11:18:00PM -0700 or thereabouts: <garyjohn@...> [2006-05-01 02:38]:
            > On 2006-05-01, cga2000 <cga2000@...> wrote:
            >
            > [...]
            >
            > > Now, after doing the above a number of times I began to think there must
            > > be a better way to handle this type of situation:
            > >
            > > 1. When I end up with (4) above, is there a better strategy than using
            > > 'J' to join line #2 and line #3 .. something that would take me
            > > directly from (4) to (9) .. hit 'A' and since the cursor would now
            > > be to the left of col. 72, continue entering my text and benefit
            > > from the wrap feature automatically?
            >
            > Yep. See
            >
            > :help gq
            > :help 25.1
            >
            > You can easily reformat the paragraph the cursor is currently in by
            > typing this in normal mode:
            >
            > gqip

            bingo..!!

            tried this very rapidly and works great - c. 2:45 AM, so I'll have to
            dig into this - and read the doc - tomorrow.. later today, I mean..

            >
            > > 2. More generally, is there a command - or sequence of commands - that
            > > would let me reformat a paragraph to take care of any line that goes
            > > beyond the limit set via the textwidth option?
            >
            > There are two approaches to this: manual and automatic. I
            > mentioned the manual technique above. You can also add the 'a' and
            > 'w' flags to 'formatoptions' and have vim automatically reflow your
            > text as you type.
            >
            > set fo+=aw
            >
            > As nice as this sounds, it has its limitations and can sometimes be
            > really infuriating. It works well enough that I have my mail.vim
            > plugin enable it, but I also have a command to disable it when it
            > gets in the way.
            >
            > HTH,

            You bet..!

            Thank you very much,

            cga
          • cga2000
            ... Not that I know of. ... and vim didn t seem to like it.. I then did a ... and formatoptions is apparently set to: formatoptions=tcql .. looks very
            Message 5 of 11 , Apr 30, 2006
            • 0 Attachment
              Thus spake Eric Arnold on Mon, May 01, 2006 at 12:19:41AM -0600 or thereabouts: <eric.p.arnold@...> [2006-05-01 02:38]:
              > Do you have these set?
              >
              > setlocal formatoptions+=bcroqan2t " better without w
              > setlocal linebreak
              >

              Not that I know of.

              I tried:

              :set ?formatoptions
              :set ?formatoptions+
              :setlocal ?formatoptions .. etc.

              and vim didn't seem to like it..

              I then did a

              :set

              and formatoptions is apparently set to:

              formatoptions=tcql

              .. looks very different from what you have above?

              I'll look into it further later today since it's really getting late.

              btw, is there any way I can direct vim to write the output of a query
              such as ':set' or ':ve' directly to the buffer? That would come in
              handy when someone asks me for more info as to how my system is
              configured.

              Thanks,

              cga
            • Gary Johnson
              ... and paste register a where you want it. Gary -- Gary Johnson | Agilent Technologies garyjohn@spk.agilent.com | Wireless Division
              Message 6 of 11 , May 1, 2006
              • 0 Attachment
                On 2006-05-01, cga2000 <cga2000@...> wrote:

                > btw, is there any way I can direct vim to write the output of a query
                > such as ':set' or ':ve' directly to the buffer? That would come in
                > handy when someone asks me for more info as to how my system is
                > configured.

                :help redir

                Example:

                :redir @a
                :set
                :redir END

                and paste register a where you want it.

                Gary

                --
                Gary Johnson | Agilent Technologies
                garyjohn@... | Wireless Division
                | Spokane, Washington, USA
              • Eric Arnold
                ... Actually, you should look at the above options, and see if you want all of them. These are what I use for when I m writing text (instead of code). ... set
                Message 7 of 11 , May 1, 2006
                • 0 Attachment
                  On 5/1/06, cga2000 <cga2000@...> wrote:
                  > Thus spake Eric Arnold on Mon, May 01, 2006 at 12:19:41AM -0600 or thereabouts: <eric.p.arnold@...> [2006-05-01 02:38]:
                  > > Do you have these set?
                  > >
                  > > setlocal formatoptions+=bcroqan2t " better without w

                  Actually, you should look at the above options, and see if you want
                  all of them. These are what I use for when I'm writing text (instead
                  of code).

                  > > setlocal linebreak
                  > >
                  >
                  > Not that I know of.
                  >
                  > I tried:
                  >
                  > :set ?formatoptions
                  > :set ?formatoptions+
                  > :setlocal ?formatoptions .. etc.

                  set formatoptions?
                  set fo?

                  You've got a dyslexic "?" :-)


                  > and vim didn't seem to like it..
                  >
                  > I then did a
                  >
                  > :set
                  >
                  > and formatoptions is apparently set to:
                  >
                  > formatoptions=tcql
                  >
                  > .. looks very different from what you have above?

                  Right. See:

                  :help fo-table

                  which describes that each of the letters means. Pay particular
                  attention to "a" and "w". I got tired of "w", so I stopped using it,
                  but you might want it.


                  > I'll look into it further later today since it's really getting late.
                  >
                  > btw, is there any way I can direct vim to write the output of a query
                  > such as ':set' or ':ve' directly to the buffer? That would come in
                  > handy when someone asks me for more info as to how my system is
                  > configured.

                  :redir @a>

                  do stuff, and when done

                  :redir end

                  Then you have everything in register "a", and can paste it where ever.

                  I'm working on a script right now which automatically transfers
                  everything to a regular buffer window. I haven't released it yet. If
                  you're interested, I can send it.
                • Eric Arnold
                  ... I think you need :redir @a or is there some kinda shortcut?
                  Message 8 of 11 , May 1, 2006
                  • 0 Attachment
                    On 5/1/06, Gary Johnson <garyjohn@...> wrote:
                    > On 2006-05-01, cga2000 <cga2000@...> wrote:
                    >
                    > > btw, is there any way I can direct vim to write the output of a query
                    > > such as ':set' or ':ve' directly to the buffer? That would come in
                    > > handy when someone asks me for more info as to how my system is
                    > > configured.
                    >
                    > :help redir
                    >
                    > Example:
                    >
                    > :redir @a

                    I think you need :redir @a> or is there some kinda shortcut?

                    > :set
                    > :redir END
                    >
                    > and paste register a where you want it.
                    >
                    > Gary
                    >
                    > --
                    > Gary Johnson | Agilent Technologies
                    > garyjohn@... | Wireless Division
                    > | Spokane, Washington, USA
                    >
                  • Gary Johnson
                    ... The at the end is new for 7.0. I don t know why it was added. The original syntax didn t have the and 7.0 accepts either. Gary -- Gary Johnson
                    Message 9 of 11 , May 1, 2006
                    • 0 Attachment
                      On 2006-05-01, Eric Arnold <eric.p.arnold@...> wrote:
                      > On 5/1/06, Gary Johnson <garyjohn@...> wrote:
                      > > On 2006-05-01, cga2000 <cga2000@...> wrote:
                      > >
                      > > > btw, is there any way I can direct vim to write the output of a query
                      > > > such as ':set' or ':ve' directly to the buffer? That would come in
                      > > > handy when someone asks me for more info as to how my system is
                      > > > configured.
                      > >
                      > > :help redir
                      > >
                      > > Example:
                      > >
                      > > :redir @a
                      >
                      > I think you need :redir @a> or is there some kinda shortcut?

                      The '>' at the end is new for 7.0. I don't know why it was added.
                      The original syntax didn't have the '>' and 7.0 accepts either.

                      Gary

                      --
                      Gary Johnson | Agilent Technologies
                      garyjohn@... | Wireless Division
                      | Spokane, Washington, USA
                    • Eric Arnold
                      ... How about that. I ve been using the beta long enough to forget how the released version works.
                      Message 10 of 11 , May 1, 2006
                      • 0 Attachment
                        On 5/1/06, Gary Johnson <garyjohn@...> wrote:
                        > On 2006-05-01, Eric Arnold <eric.p.arnold@...> wrote:
                        > > On 5/1/06, Gary Johnson <garyjohn@...> wrote:
                        > > > On 2006-05-01, cga2000 <cga2000@...> wrote:
                        > > >
                        > > > > btw, is there any way I can direct vim to write the output of a query
                        > > > > such as ':set' or ':ve' directly to the buffer? That would come in
                        > > > > handy when someone asks me for more info as to how my system is
                        > > > > configured.
                        > > >
                        > > > :help redir
                        > > >
                        > > > Example:
                        > > >
                        > > > :redir @a
                        > >
                        > > I think you need :redir @a> or is there some kinda shortcut?
                        >
                        > The '>' at the end is new for 7.0. I don't know why it was added.
                        > The original syntax didn't have the '>' and 7.0 accepts either.
                        >

                        How about that. I've been using the beta long enough to forget how
                        the released version works.
                      • Yegappan Lakshmanan
                        Hi, ... As explained in the help for :redir , for backward compatibility, ... contents of the register if its name is given uppercase {A-Z}. For backward
                        Message 11 of 11 , May 1, 2006
                        • 0 Attachment
                          Hi,

                          On 5/1/06, Gary Johnson <garyjohn@...> wrote:
                          > > >
                          > > > > btw, is there any way I can direct vim to write the output of a query
                          > > > > such as ':set' or ':ve' directly to the buffer? That would come in
                          > > > > handy when someone asks me for more info as to how my system is
                          > > > > configured.
                          > > >
                          > > > :help redir
                          > > >
                          > > > Example:
                          > > >
                          > > > :redir @a
                          > >
                          > > I think you need :redir @a> or is there some kinda shortcut?
                          >
                          > The '>' at the end is new for 7.0. I don't know why it was added.
                          > The original syntax didn't have the '>' and 7.0 accepts either.
                          >

                          As explained in the help for ":redir ", for backward compatibility,
                          the > after the register name can be omitted:

                          -----------------------------------------------------------------------------------------------
                          :redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the
                          contents of the register if its name is given
                          uppercase {A-Z}. For backward compatibility, the ">"
                          after the register name can be omitted. {not in Vi}
                          -----------------------------------------------------------------------------------------------

                          In Vim7, you can append the command output to a register (lower-case
                          register name) using the following command:

                          :redir @{a-z}>>

                          You can also redirect output to a variable using:

                          :redir => {variable}
                          :redir =>> {variable}

                          - Yegappan
                        Your message has been successfully submitted and would be delivered to recipients shortly.