title: vim: Join all lines in paragraph
body: <p>I'm trying without success to join all lines in a paragraph (block of text) using a vimscript.<br />
  I want to do this for every paragraph (block of text) and want to keep the empty lines between them.<br />
  (I don't want to use macros)</p>
  <p>When I use the <code>}w</code> command to go to the first word in the next paragraph I noted that it does not recognize empty lines with spaces or multiple empty lines between paragraphs.
  That's not what I want.</p>
  <p>So I tried this:<br />
  do a search:<br />
  <code>\(^.*\S\+.*\n\)\{2,}</code><br />
  do:<br />
  <code>normal vipgJ</code><br />
  do above search again etc.</p>
  <p>It works fine when I do it manually, but I can't put this in a script.</p>
  <p>I tried this:</p>
  <pre><code> function! &lt;SID&gt;JoinParagraphs()   
     let i = 1   
     normal gg   
     while i &lt;= 200   
     call search(&quot;\\(^.*\\S\\+.*\\n\\)\\{2,})&quot;, &quot;&quot;)   
     normal vipgJ   
      let i=i+1   
     endwhile   
    endfunction
  </code></pre>
  <p>Doesn't work...<br />
  I tried also to change the line <code>call search...</code> for<br />
  <code>let @/ = &quot;\\(^.*\\S\\+.*\\n\\)\\{2,})&quot;</code>
  but that does a Join of all lines together (doesn't keep the empty lines).</p>
  <p>What did I do wrong?</p>