Friday, July 6, 2012

Re: How to remove empty lines except of one

On Friday, July 6, 2012 12:30:09 AM UTC-5, Gautam wrote:
> On Thu, Jul 5, 2012 at 10:47 PM, Tim Chase <vim@tim.thechases.com> wrote:
> On 07/05/12 10:12, Ben Fritz wrote:
> > This replacement works for me:
> >
> > %s/^\_s\+\n/\r
>
> With the (what I'd consider beneficial) side-effect of also removing
> trailing whitespace from lines.
>
>
> I'd consider that beneficial as well, except that it doesn't remove the
> trailing whitespace in my case.
>
> I still have to use
> %s/\s\+$//
> to remove trailing whitespaces.
>
> One command to do both - get rid of multiple blank lines and trailing
> whitespace - would be super!
>

The command I gave doesn't remove trailing whitespace on non-empty lines
because of the ^ anchor in the pattern. Without it, it removes trailing
whitespace, but also removes ALL empty lines instead of leaving one empty
line behind.

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