title: In Vim, How to substitute within a subexpression?
body: <p>I want to prepend all my classNames with <code>o-</code> without having to adjust every className by hand. I use Vim.</p>
  
  <p>I know a substitution will do the job so I came up with this, which is obviously not working (and the reason I am here). </p>
  
  <pre><code>:%s/class="[^"]*"/\='class="'.substitute(submatch(0), '[^o-]*', 'o-'.submatch(1), 'g').'"'/g
  </code></pre>
  
  <p>Explanation:</p>
  
  <ol>
  <li><code>class="[^"]</code> - matches all instances of <code>class="foo bar baz"</code></li>
  <li><code>\='class="'.substitute(subexp).'"'</code> - replaces the found instances <code>class="subexp"</code></li>
  <li><code>subexp</code> in two should repace each space separated class with the original className prepended with <code>o-</code></li>
  </ol>
  
  <p>All in all, in procedural terms, for each <code>class="foo bar baz"</code>, replace each className with the className prepended with <code>o-</code>.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>(BONUS) EDIT</strong>: How can this be written to ignore or cope with classNames that already begin with <code>o-</code>, when encountered, so that <code>o-o-</code> is <strong>not</strong> a resulting edit.</p>