title: Substitution pattern to escape quotes in vim
body: <p>I have text with some lines contains properly escaped double quotes in strings and some not
  like below: </p>
  
  <pre><code>bla1 "aaa"bbb"ccc" bla1
  bla2 "aaa\"bbb\"ccc" bla2
  </code></pre>
  
  <p>The results after substitution should be </p>
  
  <pre><code>bla1 "aaa\"bbb\"ccc" bla1
  bla2 "aaa\"bbb\"ccc" bla2
  </code></pre>
  
  <p>but not:</p>
  
  <pre><code>bla1 "aaa\"bbb\"ccc" bla1
  bla2 "aaa\\"bbb\\"ccc" bla2
  </code></pre>
  
  <p>In other words it should escape the double quotes in lines where they are not escaped 
  and do not touch lines which are already properly escaped</p>
  
  <p>So far I got the second result with this</p>
  
  <pre><code>%s:\(\s".\+\)\(".\+\)\(".\+"\s\):\1\\\2\\\3:g
  </code></pre>
  
  <p>Then I've tried a negative lookbehind to tell the engine to not match 
  if there is a backslash before the quotes</p>
  
  <pre><code>(?&lt;!\) which in vim should be something like @&lt;!\
  
  %s:\(\s".\+\)\@&lt;!\\\(".\+\)@&lt;!\\\(".\+"\s\):\1\\\2\\\3:g
  </code></pre>
  
  <p>But I think I've got a little lost.</p>
  
  <p>Note:<br>
  There is only one such string per line
  The string is enclosed in double quotes and can contain double quotes inside - only this inside one should be escaped </p>