Wednesday, January 15, 2014

Re: Copy the matched substring only with :g

Hi Tim!

On Mi, 15 Jan 2014, Tim Chase wrote:

> 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

That still doesn't get all matches per line. Here is a different
approach (that needs some 7.3.600 patch or so):

:let a=[]
:%s/pattern/\=add(a,submatch(0))/gn
:call append('$', a)

Use whatever pattern you need.

Best,
Christian
--
Lehrsatz der Pioniere:
Je schwerer ein Baumstamm, desto größer sein Gewicht.

--
--
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: