See :help :g
GPG Key ID: 0x24E00D68
If it is, it should be fairly possible to do it with a :s
command, something like
> If it is, it should be fairly possible to do it with a :s
> command, something like
It should be
or, in this particular case:
because we are going to delete the whole lines that contain match, but nobody
said that they contain only match. Both solutions does not work for patterns
with \zs and \ze, maybe it is better to do the following:
function! s:MarkToDel(todelete, sline, submatch)
let lnum=len(substitute(a:submatch, '\n\@!.', '', 'g'))
call add(a:todelete, [a:sline, lnum])
execute '%s/'.escape(a:pattern, '/').
\'/\=s:MarkToDel(todelete, line("."), submatch(0))'
for [sline, lnum] in todelete
execute range.'delete _'
By the way, with some trivial modifications this code can be used in
CopyMatchingLines because it has the following advantages:
1. For each match only one search is done.
2. Pattern is compiled only once.
3. No «The 'normal! $' attempts to avoid copying the same line more than
once.»: vim does this for you when you omit /g flag (this is why 'gdefault'
option is saved and restored).
I think this will not work for the second part claimed by the comment
in the code posted: "The pattern may extend over multiple lines."
will delete only "abc", it will not delete "def".
I'm not sure how important this is to the OP...
> How should I use your function? I've copied it to my .vimrc but don't know
> what to do next :-)-
I thought that the only argument to this function is self-explanatory. Just do
to delete all lines matching pattern `abc\ndef' (they are not put in any
On Sun, Feb 6, 2011 at 18:25, ZyX <zyx...@gmail.com> wrote:
> > How should I use your function? I've copied it to my .vimrc but don't know
> > what to do next :-)-
> I thought that the only argument to this function is self-explanatory. Just do
> :call DeleteMatchingLines('abc\ndef')<CR>
> to delete all lines matching pattern `abc\ndef' (they are not put in any