Loading...

Delete lines in vi

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

vi or vim (vi improved) has powerful ways to delete line. This post gives some examples.

The command for delete is :d. Delete current line

dd

Delete line 10

:10d

Delete from start to line 30

:0,30d

Delete from line 50 to end ($)

:50,$d

Delete blank line (:g will execute a command on lines which match a regex. The regex is ‘blank line’)

:g/^$/d
vi
Please remember the terms for blog comments.