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
dinitiates the delete operator - The second
dtells Vim to apply it to the whole line (a shorthand ford_)
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
5ddto delete five lines starting from the cursor - Use
djto delete the current line and the one below it - Use
dkto delete the current line and the one above it - The deleted text goes into the default register — press
pto paste it elsewhere, effectively moving the line - Use
"_ddto delete without saving to any register (black hole register)