Removing linesin vi

I can find the lines I am looking for by searching on :blush:

but I then want to remove these lines! How can I do this easily?



position cursor on line, type in dd

to delete this line and the next 2dd

to delete the line and the next 3 type in 4dd


If you mess up type in p and the text just deleted will be “popped” back onto the screen sterting with the line after the one which the cursor is on


or use sed

Sorry I meant automatically; it’s a 14 million line file with about 7.7 million of these.

Then Kevin’s solution is the one for you.

To delete lines 13000 to 13750 for example:

To delete from start of file to current position:

To delete from current position to end of file:

bsed[/b] uses similar syntax but can run from a batch file, b man sed[/b] for details.


How about :1,$s/.*:
//g to find (and delete) lines ending with a :

Grep is your command line friend to remove that much stuff

to filter out the text
grep -v “<text to match>” >

the minus v is filter out. otherwise the default is to filter in.

egrep is your friend for complex filtering. It can contain complex logic for multiple conditions.