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

vim go to the definition

In vim rather than searching for the function definition or variable initialization you can type gd in command mode which will go to the local declaration of the word where cursor is type gD if you want to go to the global declaration.