Search This Blog

Thursday, January 23, 2020

Delete matched line with range in vim

You can use . to refer to the current line.

1) :g/foo/.,+2d will delete line with text foo and 2 lines after it

2) :g/foo/-3,.d will delete line with text foo and 3 lines before it

3) :g/foo/-1,+1d will delete line with foo, one line before it and one line after it