Vim Tips Wiki
(cleanup)
(Adjust previous/next navigation + minor manual clean)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{TipImported
 
{{review}}
 
{{Tip
 
 
|id=1012
 
|id=1012
  +
|previous=1010
|title=Quoted Printable to Plain
 
  +
|next=1014
|created=October 6, 2005 11:54
+
|created=2005
 
|complexity=intermediate
 
|complexity=intermediate
  +
|author=Bertram Scharpf
|author=vim at bertram dash scharpf dot de
 
 
|version=6.0
 
|version=6.0
 
|rating=5/2
 
|rating=5/2
  +
|category1=Email
|text=
 
  +
|category2=
 
}}
 
}}
 
Sometimes I pipe an email into Vim and then I cannot read it because it is encoded in quoted printable. Mentioning this in my vimrc helps:
 
Sometimes I pipe an E-mail into Vim and then I cannot read it because it is encoded in quoted printable. Mentioning this in my .vimrc helps:
 
   
 
<pre>
 
<pre>
 
nnoremap <Leader>Q :%s/=\(\x\x\<BAR>\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge<CR>
function s:FromQuoPri( ) range
 
exec a:firstline.",".a:lastline.'s/=\(\x\x\|\n\)/\=submatch(1)=="\n"?"":nr2char("0x".submatch(1))/ge'
+
vnoremap <Leader>Q :s/=\(\x\x\<BAR>\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge<CR>
endfunc
 
 
nnoremap &lt;silent&gt; &lt;leader&gt;Q :0/^$/+1,$call &lt;SID&gt;FromQuoPri()&lt;cr&gt;
 
 
vnoremap &lt;silent&gt; &lt;leader&gt;Q :call &lt;SID&gt;FromQuoPri()&lt;cr&gt;
 
 
</pre>
 
</pre>
 
The trick is to use a ranged function. Otherwise the = line continuations won't be substituted correctly.
 
   
 
==Comments==
 
==Comments==
How is this different from the following?
 
 
<pre>
 
nnoremap &lt;silent&gt; &lt;Leader&gt;Q :%s/=\(\x\x\&lt;BAR&gt;\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge&lt;CR&gt;
 
vnoremap &lt;silent&gt; &lt;Leader&gt;Q :s/=\(\x\x\&lt;BAR&gt;\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge&lt;CR&gt;
 
</pre>
 
 
----
 
Just a matter of taste. I didn't like to edit both lines simultaneously when developing it.
 
 
----
 

Latest revision as of 10:55, 23 September 2009

Tip 1012 Printable Monobook Previous Next

created 2005 · complexity intermediate · author Bertram Scharpf · version 6.0


Sometimes I pipe an email into Vim and then I cannot read it because it is encoded in quoted printable. Mentioning this in my vimrc helps:

nnoremap <Leader>Q :%s/=\(\x\x\<BAR>\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge<CR>
vnoremap <Leader>Q :s/=\(\x\x\<BAR>\n\)/\=submatch(1)=='\n'?'':nr2char('0x'.submatch(1))/ge<CR>

Comments[]