Sunday, November 27, 2011

Re: copy paragraphs containing

>> I suggest
>>
>> :let @z=''
>> :g/pattern/ normal "Zyap
>>
>> That would put all paragraphs in register z.
>>
>
> 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?
>

Slightly more difficult...
Maybe if you use an intermediate stage where you replace every
instance of the pattern - except on the first line on which it occurs
in each paragraph - with something else. Then run the command I
suggested, and finally replace everything back.

This will replace the pattern with PATTERN, one every line in a
paragraph except the first line on which it occurs
:g/pattern/ +,/^$/ s/pattern/\U&/g

--
Albin Olsson, IT Consultant and Classic Connoisseur
www.albinolsson.se | albin.olsson@gmail.com
+46 707 831 830

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