Marczis, Peter (NSN - HU/Budapest) wrote:
I usually do it this way:

:v/my pattern/d<CR>

and it works perfect to any single line pattern...

my problem is that I want to keep something like this:

ABC ...
....
....
...
And until the first empty line...

How it is possible ? I was thinking something like this:
:v/ABC\(.|\n)*^\s*$/d

but not really work.

My first thought would be to use a "decorate-modify-undecorate" pattern, something like

  :g/ABC/,/^\s*$/-s/^/@

"on every line matching ABC, from that line through the next blank line (minus one = "-", which you can remove if you want to keep the blank lines), tack a '@' character at the beginning of the line" (mark the lines we want to keep with a unique character)

  :v/^@/d

"delete all the lines we didn't mark as interesting"

  :%s/^@

"remove all the decoration we put in".

It requires being able to find a decoration character that isn't in use at the beginning of any line, so you might have to use "%" or some other character instead, but the pattern is the same.

As a side note, it does require at least one blank line after the each ABC or you'll get a little complaint from Vim. It also has difficulty if you have more than one ABC in a section such as

  ABC
  foo
  ABC  <-- there's no blank line above this
  bar      so the overlap with the first ABC
           causes problems

  ABC
  ...

-tim



--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to