title: function in vim to fix quotations
body: <p>I'm trying to create a function in vim to be activated by a shortcut and go through my document and re-quote the strings using Python-like syntax. That is:</p>
  <ul>
  <li><code>&quot;something&quot;</code> -&gt; <code>'something'</code></li>
  <li><code>'''docstring'''</code> -&gt; <code>&quot;&quot;&quot;docstring&quot;&quot;&quot;</code></li>
  <li><code>&quot;'&quot;</code> -&gt; <code>&quot;'&quot;</code> (stays the same)</li>
  <li><code>'&quot;'</code> -&gt; <code>'&quot;'</code> (stays the same)</li>
  </ul>
  <p>Given my limited knowledge of python functions I came up with this in my <code>.vimrc</code>:</p>
  <pre><code>function! Fixquotes()
     :silent! %s/&quot;\([^&quot;]*\)&quot;/'\1'/g
     :silent! %s/'&quot;&quot;/&quot;&quot;&quot;/
     :silent! %s/&quot;&quot;'/&quot;&quot;&quot;/
     :silent! %s/'''/&quot;&quot;&quot;/g
  endfunction
  
  inoremap &lt;C-f&gt; &lt;esc&gt;mk:call Fixquotes()&lt;CR&gt;`kli
  noremap &lt;C-f&gt; mk:call Fixquotes()&lt;CR&gt;`k
  </code></pre>
  <p>It kinda work, except for the case where I have <code>&quot;'&quot;</code> since the first substitution will turn it into <code>'''</code> and the last will turn it into <code>&quot;&quot;&quot;</code>.</p>
  <p>Does anyone have any recommendation?</p>