Vim Tips Wiki
(Added some missing patterns to manage end-of-line spaces.)
(Adjust previous/next navigation)
 
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:
 
{{TipImported
 
{{TipImported
 
|id=948
 
|id=948
|previous=947
+
|previous=946
 
|next=949
 
|next=949
 
|created=June 8, 2005
 
|created=June 8, 2005
Line 14: Line 14:
 
I frequently get email from people who do not use format-flowed email properly. I prefer to send out "correct" email, including the stuff I'm quoting, and Vim helps me do that. I added this function to my vimrc, and now I use it when editing mail by simply typing:
 
I frequently get email from people who do not use format-flowed email properly. I prefer to send out "correct" email, including the stuff I'm quoting, and Vim helps me do that. I added this function to my vimrc, and now I use it when editing mail by simply typing:
   
<pre>
+
<code>
  +
:Fixq
:call FixFlowed()
 
</pre>
+
</code>
 
That's easier to type, because I really type :call F&lt;tab&gt;
 
   
 
Here's the function:
 
Here's the function:
Line 25: Line 23:
 
function! Fixflowed()
 
function! Fixflowed()
 
" save cursor position
 
" save cursor position
let pos = getpos(".")[1:]
+
let pos = getpos(".")
 
" add spaces to the end of every line
 
" add spaces to the end of every line
 
silent! %s/\([^]> :]\)\ze\n>[> ]*[^> ]/\1 /g
 
silent! %s/\([^]> :]\)\ze\n>[> ]*[^> ]/\1 /g
Line 39: Line 37:
 
endwhile
 
endwhile
 
" restore the original cursor location
 
" restore the original cursor location
call cursor(pos)
+
call setpos('.',pos)
 
endfunction
 
endfunction
 
</pre>
 
</pre>
   
It's a little sensitive because it blows away ascii art, and it also doesn't automatically reflow paragraphs (I have no idea how to do that properly). Hope it helps someone.
+
It's a little sensitive because it CAN blow away ascii art (it tries not to), and it also doesn't automatically reflow paragraphs (I have no idea how to do that properly).
  +
  +
I also have another function that helps when inserting indented paragraphs into a format=flowed email; the idea is to remove spaces at the end of indented lines so that they won't be wrapped (quoting is not indenting):
  +
  +
<pre>
  +
function! Fixindented()
  +
" remove spaces at end of indented lines
  +
silent! %s/^\s.*\zs \+$//
  +
endfunction
  +
</pre>
  +
  +
I set these functions up like this:
  +
  +
<pre>
  +
autocmd Filetype mail command! Fixq call Fixflowed()
  +
autocmd Filetype mail autocmd BufWritePre <buffer> call Fixindented()
  +
</pre>
  +
  +
Hope it helps someone.
   
 
==Comments==
 
==Comments==

Latest revision as of 03:12, 30 June 2008

Tip 948 Printable Monobook Previous Next

created June 8, 2005 · complexity intermediate · author Kyle Wheeler · version 5.7


I frequently get email from people who do not use format-flowed email properly. I prefer to send out "correct" email, including the stuff I'm quoting, and Vim helps me do that. I added this function to my vimrc, and now I use it when editing mail by simply typing:

Fixq

Here's the function:

function! Fixflowed()
  " save cursor position
  let pos = getpos(".")
  " add spaces to the end of every line
  silent! %s/\([^]> :]\)\ze\n>[> ]*[^> ]/\1 /g
  " remove extraneous spaces
  silent! %s/ \+\ze\n[> ]*$//
  " make sure there's only ONE space at the end of each line
  silent! %s/ \{2,}$/ /
  " fix the wockas spacing from the text
  silent! %s/^[> ]*>\ze[^> ]/& /
  " compress the wockas
  while search('^>\+ >', 'w') > 0
    s/^>\+\zs >/>/
  endwhile
  " restore the original cursor location
  call setpos('.',pos)
endfunction

It's a little sensitive because it CAN blow away ascii art (it tries not to), and it also doesn't automatically reflow paragraphs (I have no idea how to do that properly).

I also have another function that helps when inserting indented paragraphs into a format=flowed email; the idea is to remove spaces at the end of indented lines so that they won't be wrapped (quoting is not indenting):

function! Fixindented()
  " remove spaces at end of indented lines
  silent! %s/^\s.*\zs \+$//
endfunction

I set these functions up like this:

autocmd Filetype mail command! Fixq call Fixflowed()
autocmd Filetype mail autocmd BufWritePre <buffer> call Fixindented()

Hope it helps someone.

Comments[]

PAR is a lot better at this kind of thing: http://www.nicemice.net/par/


PAR is a useful tool, but is not specific to format=flowed, and so can be over-zealous in some cases. For example, it doesn't recognized the -- separator between email body and signature, and wraps it into the signature.