Wednesday, January 15, 2014

Re: Copy the matched substring only with :g

2014-01-15 15:29, Paul Isambert skrev:
> "BPJ" <bpj@melroch.se>:
>> Is there any way when using :g to copy the matched substring only?
>>
>> I want to find all lines with CamelCase words and copy those
>> words to the bottom of the buffer.
>>
>> :g/\a*\l\U\a*/t$
>>
>> copies the whole line, but I want to get the part of the line
>> matching the pattern.
>
> Quick solution:
>
> g/\a*\(\l\u\|\u\l\)\a*/call setline(line('$')+1, matchstr(getline('.'), '\a*\(\l\u\|\u\l\)\a*'))

Thanks!

> Notes:
> - I've replaced \U with \u, since \U means [^A-Z].

D'oh I make that one all the time...

> - I've replaced \l\u with \(\l\u\|\u\l\), otherwise words starting with an
> uppercase letter won't be found.

Why so? Doesn't the \a* take care of it?

>
> Best,
> Paul
>

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