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

Re: Line break without \n or \r?

Expand Messages
  • Paul Isambert
    Hello Paul, ... works ok. To me, [^ n] doesn t mean much ( [^ n] would be better), and anyway your original form corrected wouldn t work either for
    Message 1 of 5 , Apr 6, 2013
    • 0 Attachment
      Hello Paul,

      Paul <pywpeng@...> a écrit:
      > I was puzzled by the second line break in the attached file. I want to
      > connect all lines that are next to each other (ie there is no blank
      > lines between them, the same way how tex defines a paragraph). So I
      > issue the following command:
      >
      > :%s/\([^\\n]\)\n\([^\\n]\)/\1 \2/g
      >
      > However, the result is
      >
      > uuuu An
      > by y
      >
      > Clearly there is something right after "An" that is not \n but produces
      > a line break. I also tried to replace \n with \r in the command, but it
      > does not work either. I tried various ways but could not find a reason
      > why the above command fails at the second line.

      This:

      :%s/.\zs\_s\ze./ /g

      works ok. To me, "[^\\n]" doesn't mean much ("[^\n]" would be better),
      and anyway your original form corrected wouldn't work either for
      one-character lines (since that character would be used by the pattern
      to join the current line to the previous one, and couldn't be reused
      to join the current line to the next one).

      > I find this issue when I tried to connect all the lines in a texfile
      > that forms a paragraph. There are always some lines that failed to be
      > connected and I can't seea reason. Anyone has a clue about this issue?

      A simpler way is to use "vipJ", meaning "select the current paragraph
      and join the lines" (see ":help v_j").

      Best,
      Paul

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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Paul
      Thank you Paul for your great suggestions. Even though I still don t quite understand why my command fails at seemingly random places, it is not important, and
      Message 2 of 5 , Apr 6, 2013
      • 0 Attachment
        Thank you Paul for your great suggestions. Even though I still don't quite understand why my command fails at seemingly random places, it is not important, and your command works beautifully for my purpose.

        I know the second method you mentioned. But I prefer the first method because I don't want to manually go to every paragraph to join the lines.

        Thanks a lot.
        Paul.


        On Saturday, April 6, 2013 3:17:01 AM UTC-4, Paul Isambert wrote:
        > Hello Paul,
        >
        >
        >
        > Paul a ï¿œcrit:
        >
        > > I was puzzled by the second line break in the attached file. I want to
        >
        > > connect all lines that are next to each other (ie there is no blank
        >
        > > lines between them, the same way how tex defines a paragraph). So I
        >
        > > issue the following command:
        >
        > >
        >
        > > :%s/\([^\\n]\)\n\([^\\n]\)/\1 \2/g
        >
        > >
        >
        > > However, the result is
        >
        > >
        >
        > > uuuu An
        >
        > > by y
        >
        > >
        >
        > > Clearly there is something right after "An" that is not \n but produces
        >
        > > a line break. I also tried to replace \n with \r in the command, but it
        >
        > > does not work either. I tried various ways but could not find a reason
        >
        > > why the above command fails at the second line.
        >
        >
        >
        > This:
        >
        >
        >
        > :%s/.\zs\_s\ze./ /g
        >
        >
        >
        > works ok. To me, "[^\\n]" doesn't mean much ("[^\n]" would be better),
        >
        > and anyway your original form corrected wouldn't work either for
        >
        > one-character lines (since that character would be used by the pattern
        >
        > to join the current line to the previous one, and couldn't be reused
        >
        > to join the current line to the next one).
        >
        >
        >
        > > I find this issue when I tried to connect all the lines in a texfile
        >
        > > that forms a paragraph. There are always some lines that failed to be
        >
        > > connected and I can't seea reason. Anyone has a clue about this issue?
        >
        >
        >
        > A simpler way is to use "vipJ", meaning "select the current paragraph
        >
        > and join the lines" (see ":help v_j").
        >
        >
        >
        > Best,
        >
        > Paul

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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • zappathustra@...
        ... Now I understand, and it s actually quite simple. The pattern ([^ n] ) n ([^ n] ) means two characters separated by a new line, and those characters
        Message 3 of 5 , Apr 6, 2013
        • 0 Attachment
          Paul <pywpeng@...> a écrit:
          > Thank you Paul for your great suggestions. Even though I still don't quite
          > understand why my command fails at seemingly random places,

          Now I understand, and it's actually quite simple. The pattern

          \([^\\n]\)\n\([^\\n]\)

          means two characters separated by a new line, and those characters
          must be neither a backslash nor an "n". Your original file was

          uuuu
          An
          by
          y

          and you ended up with

          uuuu An
          by y

          because the "n" at the end of the first line was excluded from the
          pattern.

          Best,
          Paul

          > it is not
          > important, and your command works beautifully for my purpose.
          >
          > I know the second method you mentioned. But I prefer the first method because
          > I don't want to manually go to every paragraph to join the lines.
          >
          > Thanks a lot.
          > Paul.
          >
          >
          > On Saturday, April 6, 2013 3:17:01 AM UTC-4, Paul Isambert wrote:
          > > Hello Paul,
          > >
          > >
          > >
          > > Paul a ï¿œcrit:
          > >
          > > > I was puzzled by the second line break in the attached file. I want to
          > >
          > > > connect all lines that are next to each other (ie there is no blank
          > >
          > > > lines between them, the same way how tex defines a paragraph). So I
          > >
          > > > issue the following command:
          > >
          > > >
          > >
          > > > :%s/\([^\\n]\)\n\([^\\n]\)/\1 \2/g
          > >
          > > >
          > >
          > > > However, the result is
          > >
          > > >
          > >
          > > > uuuu An
          > >
          > > > by y
          > >
          > > >
          > >
          > > > Clearly there is something right after "An" that is not \n but produces
          > >
          > > > a line break. I also tried to replace \n with \r in the command, but it
          > >
          > > > does not work either. I tried various ways but could not find a reason
          > >
          > > > why the above command fails at the second line.
          > >
          > >
          > >
          > > This:
          > >
          > >
          > >
          > > :%s/.\zs\_s\ze./ /g
          > >
          > >
          > >
          > > works ok. To me, "[^\\n]" doesn't mean much ("[^\n]" would be better),
          > >
          > > and anyway your original form corrected wouldn't work either for
          > >
          > > one-character lines (since that character would be used by the pattern
          > >
          > > to join the current line to the previous one, and couldn't be reused
          > >
          > > to join the current line to the next one).
          > >
          > >
          > >
          > > > I find this issue when I tried to connect all the lines in a texfile
          > >
          > > > that forms a paragraph. There are always some lines that failed to be
          > >
          > > > connected and I can't seea reason. Anyone has a clue about this issue?
          > >
          > >
          > >
          > > A simpler way is to use "vipJ", meaning "select the current paragraph
          > >
          > > and join the lines" (see ":help v_j").
          > >
          > >
          > >
          > > Best,
          > >
          > > Paul
          >
          > --
          > --
          > 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
          >
          > ---
          > You received this message because you are subscribed to the Google Groups "vim_use" group.
          > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          > For more options, visit https://groups.google.com/groups/opt_out.
          >
          >

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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Bee
          ... Finds a linefeed followed by a non-linefeed and replaces the linefeed with a space. Changes this: ============= uuuu An by y uuuu An by y To this: ========
          Message 4 of 5 , Apr 6, 2013
          • 0 Attachment
            On Apr 6, 2:10 pm, zappathus...@... wrote:
            > Now I understand, and it's actually quite simple.
            > The pattern
            >     \([^\\n]\)\n\([^\\n]\)
            > ...
            > and you ended up with
            >     uuuu An
            >     by y
            > because the "n" at the end of the first line was excluded
            > from the pattern.

            Can be simplified to:

            :%s/\n\([^\n]\)/ \1/

            Finds a linefeed followed by a non-linefeed
            and replaces the linefeed with a space.

            Changes this:
            =============

            uuuu
            An
            by
            y

            uuuu
            An
            by
            y

            To this:
            ========

            uuuu An by y
            uuuu An by y

            Then if needed, a second search/replace to
            separate 'paragraphs' by at most one blank line:

            :%s/\n\+/\r\r/

            To this:
            ========

            uuuu An by y

            uuuu An by y

            Bill

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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          Your message has been successfully submitted and would be delivered to recipients shortly.