Wednesday, July 18, 2012

Re: How to remove empty lines except of one

On Wednesday, July 18, 2012 3:35:56 PM UTC-5, Bee wrote:
> On Jul 18, 12:46 pm, Ben Fritz <fritzophre...@gmail.com> wrote:
> > On Tuesday, July 17, 2012 7:27:42 PM UTC-5, Bee wrote:
> > > This will collapse multiple blank lines,
> > > remove trailing white space, and
> > > leave only one blank line at the end of file.
> >
> > > %s-\_s\+$-\r
> >
> > > Bill
> >
> > I found the problem with this one. :help /$ indicates that the $ is zero-width, so the end of line is not included in the match, therefore on the two blank lines at the beginning of the file, only the first is included in the match.
> >
> > So, this works exactly as I think it should:
> >
> > %s-\_s\+\n-\r
> >
> > Note this is almost identical to my first proposed solution, except that it is missing the beginning of line anchor. I'm not sure what makes it fail with the ^ in place.
>
> osx terminal vim 7.3.584
>
> %s-\_s\+\n-\r
>
> Removes ALL blank lines,
> rather than collapsing multiple blank lines into one 'blank' line.
>
> I still want one blank line between 'paragraphs'.

Oh right...that's why the ^ was there in the first place. Now I remember :-)

So, it's still a special case if the first or last line is blank. Instead of removing all blank lines, it leaves one blank line in its place at the beginning and end.

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

No comments: