How to delete a line in Vim
In Normal mode, put the cursor anywhere on the line and press dd. A count deletes more: 3dd deletes this line and the two below it.
Take out the debug lines
Two console.log lines were left behind. The cursor is on the first one: dd it, then move down to the second and do the same.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | Deletes |
|---|---|
| dd | the line the cursor is on |
| 3dd | three lines, starting with this one |
| dj / dk | this line and the one below / above |
| dG | from this line to the end of the file |
| dgg | from this line to the top of the file |
| d} | to the next blank line (the rest of the paragraph) |
:d ↵ | the current line, from the command line |
:5,10d ↵ | lines 5 to 10 |
:g/console/d ↵ | every line that contains console |
| "_dd | the line, without copying it anywhere (see below) |
function total(items) { console.log('items', items); let sum = 0; console.log('start'); for (const i of items) sum += i.price; return sum;}function total(items) { let sum = 0; for (const i of items) sum += i.price; return sum;}Deleting is cutting
A deleted line isn't gone: Vim puts it in a register, the way a cut puts text on a clipboard. p puts it back below the cursor and P above, so dd then p moves a line down one, and dd somewhere else then p moves it anywhere.
That's handy until you delete a line and then want to paste something you copied earlier: the delete replaced it. Delete into the "black hole" register instead, "_dd, and your copy stays where it was. (Your earlier copy is also still in register 0: "0p.)