Re: Copying matched parts of lines
- On 2013-03-26 16:56, Christian Brabandt wrote:
> On Tue, March 26, 2013 16:43, BPJ wrote:I believe Christian's comment about the "recent enough Vim" involves
> > 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 = 
> call add(g:a, a:match)
> :new +put\ =g:a
the /n flag actually executing the replacement if it's a
sub-replace-special (earlier versions didn't, IIRC). If that's the
case, the function can be modified to simply return the match:
call add(g:a, a:match)
It may have the unfortunate side-effect of setting 'modified' when all
the modifications were NOOPs, but you can either simply undo the
non-modification, or you can force the setting of 'nomodified'.
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@....
For more options, visit https://groups.google.com/groups/opt_out.