 <p>A generic approach:</p> <pre><code>:%s/\(&lt;string name="\)\(\u\)\([^" ]\+\) \([^" ]\+\)/\1\l\2\e\3_\4/ </code></pre> <p>This replaces every string @name that </p> <ul> <li>starts with an upper case character (<code>\u</code>) and</li> <li>consists of two space-separated words (<code>\([^" ]\+\) \([^" ]\+\)</code>) and </li> <li>replaces it with the corresponding lower-case character (<code>\l\2\e</code>). </li> <li>It also replaces the space with an underscore.</li> </ul> <hr> <p>To make everything in @name lower-case, this could be simplified:</p> <pre><code>:%s/\(&lt;string name="\)\([^" ]\+\) \([^" ]\+\)/\1\l\2_\3_\e/ </code></pre> <hr> <p>To get rid of multiple spaces, do two steps. First, make the attribute value lower-case:</p> <pre><code>:%s/\(&lt;string name="\)\([^"]\+\)/\1\l\2\e/ </code></pre> <p>then, replace every space in the attribute value with an underscore</p> <pre><code>:%s/\(&lt;string name="[^"]*\)\@&lt;= /_/g </code></pre> <p>Note that the <code>\@&lt;=</code> is vim's way of expressing a positive look-behind assertion.</p>