Thursday, July 5, 2012

Re: How to remove empty lines except of one

On Thursday, July 5, 2012 7:15:43 AM UTC-5, Gautam wrote:
> On Thu, Jul 5, 2012 at 4:24 PM, Tim Chase wrote:
> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As for blank-ish lines (containing just whitespace), it might become
>
>
>
> something like
>
>
>
>  %s/^\(\s*\n\)\+/\r
> <font color="#888888">
> </font></blockquote>
>
> </div>
> I added this to my .vimrc as:</div>
>
> </div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
>
>
>
> command RemoveMultipleBlankLines %s/^\(\s*\n\)\+/\r</div>
>
> </div></div></blockquote>Now &quot;:RemoveMultipleBlankLines&quot; works like it should except when my file has a blank line at the very end.
> In this case, I get 2 blank lines at the end.</div>
>
>
> Any idea how I can prevent that?</div>
>
> </div>
> - Gautam</div>
>
> </div>

This replacement works for me:

%s/^\_s\+\n/\r

I'm not actually sure why your version doesn't work, but I see the same behavior.

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