snipt

Ctrl+h for KB shortcuts

VimL

camelCase to under_score notation regex (vim)

%s/\<\u\|\l\u/\=len(submatch(0)) == 1 ? tolower(submatch(0)) : submatch(0)[0].'_'.tolower(submatch(0)[1])/gc
https://snipt.net/embed/02d6e4bda7d78ebbb723ac5fd2159fed/
/raw/02d6e4bda7d78ebbb723ac5fd2159fed/
02d6e4bda7d78ebbb723ac5fd2159fed
vim
VimL
1
2019-07-22T22:31:53
True
False
False
Feb 18, 2013 at 06:48 AM
/api/public/snipt/31541/
camelcase-to-underscore
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>%s<span class="sr">/\&lt;\u\|\l\u/</span>\<span class="p">=</span>len<span class="p">(</span>submatch<span class="p">(</span><span class="m">0</span><span class="p">))</span> <span class="p">==</span> <span class="m">1</span> ? tolower<span class="p">(</span>submatch<span class="p">(</span><span class="m">0</span><span class="p">))</span> : submatch<span class="p">(</span><span class="m">0</span><span class="p">)</span>[<span class="m">0</span>].<span class="s1">&#39;_&#39;</span>.tolower<span class="p">(</span>submatch<span class="p">(</span><span class="m">0</span><span class="p">)</span>[<span class="m">1</span>]<span class="p">)</span>/gc </span></pre></div> </td></tr></table>
camel_case, vim