Saturday, April 6, 2013

Re: Line break without \n or \r?

Paul <pywpeng@gmail.com> 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@googlegroups.com.
> 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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: