Vim

Delete lines

Delete single line

dd

Delete all lines

:1,$d or:%d

Delete multiple lines

Prefix the dd command with the number of lines you want to delete below it.

If you want to delete 3 consecutive lines below:# 3dd

Delete lines by a given pattern

Delete lines that contain a certain word, press ESC and run

:g /word/d

Delete every line that doesn't contain the word "lazy"

:%g!/lazy/d or :v/lazy/d

Delete lines that begin with a certain letter, say 'A'

:g/^A/d

Delete lines that begin with a special character like $ sign, prefix the character with a backslash

:g/^\$/d

Get rid of all blank lines

:g/^$/d

Last updated