Tuesday, March 26, 2013

Re: Copying matched parts of lines

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('.'), @/)

(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.

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