Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all lines after line N that match "ABC"

Tags:

vim

Say I'm editing a 1000 line file.

I want to keep lines 1-500 untouched.

But I want to delete all lines after line 500 that match "ABC"

How can i do this?

I can do all lines line this

:g/ABC/d

And i can delete all lines in range

:501,$d

But how to delete only lines that match a pattern?

(Been using vi since 1989. Just can't think how to do this! Sorry if it's obvious)

like image 532
Rob Avatar asked Dec 12 '22 12:12

Rob


1 Answers

:global takes a range, too. Thus you want:

501,$g/ABC/d :-)

like image 170
mhinz Avatar answered Feb 01 '23 06:02

mhinz