vimtricks.wiki Concise Vim tricks, one at a time.

How do I delete an entire line in Vim?

Answer

dd

Explanation

The dd command deletes the entire current line, regardless of where the cursor is positioned on that line. The deleted line is stored in the default register, so you can paste it elsewhere with p.

How it works

  • The first d initiates the delete operator
  • The second d tells Vim to apply it to the whole line (a shorthand for d_)

Example

Given the text:

line one
line two
line three

With the cursor on line two, pressing dd results in:

line one
line three

Tips

  • Use 5dd to delete five lines starting from the cursor
  • Use dj to delete the current line and the one below it
  • Use dk to delete the current line and the one above it
  • The deleted text goes into the default register — press p to paste it elsewhere, effectively moving the line
  • Use "_dd to delete without saving to any register (black hole register)

Next

How do I edit multiple lines at once using multiple cursors in Vim?