Tuesday, April 15, 2014

Re: Extra lines in Google Groups reply [Was: my invisible characters are not displayed properly]

On 04/15/2014 03:02 PM, Ben Fritz wrote:
> On Tuesday, April 15, 2014 10:46:28 AM UTC-5, Gary Johnson wrote:
>>
>> Would you please trim all the extra newlines that keep accumulating
>> in your replies?

> Anyway...what is an efficient way in Vim to deal with this?
> The best I came up with, was to record a macro on an extra
> newline that just did "ddj" and then run that macro with a
> count of 9999. It seems kludgy though and I'm always afraid
> I'll trim too much.

Based on a posting from Andy Wokula some time ago, I've got a
"delete rubbish whitespace" mapping in my vimrc (shown below).
For your use case, the interesting part is the ability to select
a run of consecutive whitespace lines using "ip". With your
cursor in the run of blank lines, "dip" (or "dvip" as Andy's
mapping uses) selects and deletes the blank lines. It can seem
counter-intuitive that the "inner paragraph" being selected
consists of nothing but whitespace, but it's also convenient :-)

The mapping is below. I don't remember how much I changed
Andy's logic, so if something looks wrong below, it's likely my
fault, not his:

" Remove "rubbish" whitespace (from Andy Wokula posting).

nnoremap <silent> drw :<C-U>call DeleteRubbishWhitespace()<CR>

function! DeleteRubbishWhitespace()
" Reduce many spaces or blank lines to one.
let saveVirtualEdit = [&virtualedit]
set virtualedit=
let line = getline(".")
if line =~ '^\s*$'
let savePos = winsaveview()
let saveFoldEnable = &foldenable
setlocal nofoldenable
normal! dvip0D
let savePos.lnum = line(".")
let &l:foldenable = saveFoldEnable
call winrestview(savePos)
elseif line[col(".")-1] =~ '\s'
normal! zvyiw
if @@ != " "
normal! dviwr m[
" m[ is just to avoid a trailing space
endif
endif
let [&ve] = saveVirtualEdit
" Uncomment the line below if you have the repeat plugin.
" silent! call repeat#set("drw")
endfunction

Michael Henry

--
--
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/d/optout.

No comments: