Sunday, November 27, 2011

Re: copy paragraphs containing

On Nov 27, 1:46 pm, Tim Chase <v...@tim.thechases.com> wrote:
> On 11/27/11 13:38, Bee wrote:
>
> > Thank you. That works but if there is more than one occurrence
> > of / pattern/ in the paragraph, the paragraph is copied 'N'
> > times. Is there a way to get only one copy of the paragraph?
>
> You might want to try something like
>
>   :let @a=''|g/^\(\%^\|\n\)\(.\+\n\)*.*Regexp/;'}y A
>
> which searches for paragraph-starts that contain "Regexp" within
> the paragraph.  It then yanks from that beginning-of-paragraph to
> the next paragraph-end, appending to register "a" (which we clear
> out at the beginning.
>
> -tim

I tried to break out the pieces.
Does the ';' mean perform another search?

:let @a=''|g/^\(\%^\|\n\)\(.\+\n\)*.*foo/;'}y A

\%^ Matches start of the file
When matching with a string matches the start of the string
example, to find the first "VIM" in a file: /\%^\_.\{-}\zsVIM
\| A pattern is one or more branches
; Perform another search
'{ `{ To the start of the current paragraph

-Bill

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

No comments:

Post a Comment