Thursday, March 28, 2013

Fwd: Re: Copying matched parts of lines

Dang! Seems I sent this directly to Tim!
Please accept my apologies!

/bpj

On 2013-03-26 16:58, Tim Chase wrote:
> On 2013-03-26 16:43, BPJ wrote:
>> Is it somehow possible with :g// to copy only the
>> matched parts of lines as with the -o option of grep?
>
> Not elegantly, but it can be done:
>
> :let @a=''|g/pattern/let @a=@a." ".matchstr(getline('.'), @/)

Thought: Could the part after the second slash somehow be wrapped
into a command and/or a function?

:let @a=''|g/pattern/Gather(@a,"\n")

but can you pass around a register like that?

>
> (you can change the joining string from " " to "\n" if you want each
> match on its own line in the gathered results)
>
> This will accumulate the matches in register "a" for your pasting
> pleasure.
>
> It will only do the first match, as you'd have to better define the
> behavior you want if there are multiple matches on the same line.

I think I sometimes would want them all, sometimes only the first.

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