Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove lines from buffer that match the selected text

Tags:

regex

vim

When analyzing large log files, I often remove lines containing text I find irrelevant:

:g/whatever/d

Sometimes I find text that spans multiple lines, like stacktraces. For that, I record the steps taken (search, go to start anchor, delete to end anchor) and replay that macro with 100000@q. I'm searching for a function or a feature vim already has included that allows me to mark text and remove all lines containing this text. Ideally this would also work for block selection.

like image 702
steffen Avatar asked May 02 '26 23:05

steffen


1 Answers

If I understood your problem right, this command should do what you want:

:g/NullPointer/,/omitt/d

Example:

Before:

1
2
3
NullPointerException1
4
5
6
omitted
7
NullPointerException2
8
9
omitted
10

After:

1
2
3
7
10

Please read :h edit-paragraph-join, there is good explanation for the command, your case is just changing join into d

like image 182
Kent Avatar answered May 05 '26 13:05

Kent