Based on our discussion in the comments, I guess a "block" means several complete lines. If the first and last lines are distinctive, then the method you gave in the comments should work. (By "distinctive" I mean that there is no danger that these lines occur anywhere else in your log file.)
For simplifications, I would use "ay$
to yank the first line into register a
and "by$
to yank the last line into register b
instead of using Visual mode. (I was going to suggest "ayy
and "byy
, but that wold capture the newlines)
To be on the safe side, I would anchor the patterns: /^{text}$/
just in case the log file contains a line like "Note that {text} marks the start of the Java exception." On the command line, I would use <C-R>a
and <C-R>b
to paste in the contents of the two registers, as you suggested.
:g/^<C-R>a$/,/^<C-R>b$/d
What if the yanked text includes characters with special meaning for search patterns? To be on the really safe side, I would use the \V
(very non-magic) modifier and escape any slashes and backslashes:
:g/\V\^<C-R>=escape(@a, '/\')<CR>\$/,/\V\^<C-R>=escape(@b, '/\')<CR>\$/d
Note that <C-R>=
puts you on a fresh command line, and you return to the main one with <CR>
.
It is too bad that \V
was not available when matchit was written. It has to deal with text from the buffer in a search pattern, much like this.