Wednesday, January 15, 2014

Re: Copy the matched substring only with :g

On 2014-01-15 15:29, Paul Isambert wrote:
> g/\a*\(\l\u\|\u\l\)\a*/call setline(line('$')+1,
> matchstr(getline('.'), '\a*\(\l\u\|\u\l\)\a*'))


Riffing off Paul's solution, I'd suggest

:g/\<\w*\l\u\w*\>/call setline(line('$')+1, matchstr(getline('.'), @/))

which removes the need to specify the pattern twice, using the "/"
register to specify it to matchstr.

The regexp can be tweaked (I chose the above as my "there's something
camelCase" regexp), but there are cases you'd have to make a
determination on camelCase'ness:

HTMLobject
MyObject
_myProperty
_MyObject
InnerHTML
THIS_IS_HTML

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment