How to delete all paragraphs where a pattern is not present?
vim
Solution
This works:
let @r="" | execute("g/acme/ normal \"Rdap") | %d | put r
It goes to every paragraph containing "acme", and delete it appending to register r. Then deletes everything and puts register r.
As you see, basic trick is using capital letter register to add to it, instead of replacing its content. This also requires resetting the register at the beginning, to discard previous register contents.
This works ok for paragraphs with multiple occurrences of "acme", as the whole paragraph is deleted after the first match, and so, it's not matched again.
Problem
I keep a log-book of the meetings in which I took part. Each meeting : - is separated by a blank line (-> each meeting is a paragraph) - is folded thanks to an expression - contains a line with the corresponding tags : ACME, GMBH, SARL, etc… When I want to make a review of all the meetings I had with, e.g., ACME, - I create a scratch buffer (:%y, followed by :tabnew, followed by paste) - and I wish to eliminate all paragraphs where ACME does not figure. This is where I have a problem. I know how to search/delete by lines : ``` :v/ACME/d ``` But how do I do that by paragraph (so as to keep the whole paragraph where ACME figures, and not the only line of tags) ? NB : the pattern ACME can figure more than once in those paragraphs.