Tuesday, March 26, 2013

Re: Copying matched parts of lines

On Tue, March 26, 2013 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?
>
> /bpj

With a recent enough Vim, you can make use of :s command and execute VimL
on the replacement part while not modifying the match (by using the 'n'
flag):


fu! CopyMatches(match)
if !exists("g:a")
let g:a = []
endif
call add(g:a, a:match)
endfu

:%s/foobar/\=CopyMatches(submatch(0))/gn
:new +put\ =g:a


regards,
Christian

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