title: Replace ‘&’ not at end of line and not preceded by ‘\’ with ‘\&’ in Vim
body: <p>I need to replace <code>&amp;</code> with <code>\&amp;</code> when <code>&amp;</code> is not at the end of the line and it is not preceded by <code>\</code>. I can successfully find <code>&amp;</code> when it is not preceded by <code>\</code>, but I can not exclude those that are at the end of the line.</p>
  
  <pre><code>line 1 &amp;
  line 2
  line 3 another &amp;
  line 4 &amp; is at the middle
  </code></pre>
  
  <p>In above four lines, I only want to replace <code>&amp;</code> with <code>\&amp;</code> at line 4.</p>
  
  <p>How could I do that?</p>
  
  <p>Here is what I can do so far:</p>
  
  <pre><code>/\(\\\)\@&lt;!&amp;
  </code></pre>
  
  <p>Find <code>&amp;</code> when it is not preceded by <code>\</code>. By adding negative lookahead <code>\@!$</code>, that is using:</p>
  
  <pre><code>/\(\\\)\@&lt;!&amp;\@!$
  </code></pre>
  
  <p>I should get those <code>&amp;</code> that are not at the end of the line, but I can not.</p>