How to delete to the end of a line in Vim
In Normal mode, press D to delete from the cursor to the end of the line. It is short for d$; C does the same and leaves you in Insert mode to type the replacement.
Trim a comment, rewrite a value
The cursor is just before an old comment: D removes it. Then on the next line, go back to the quote and use C to replace the hard-coded URL with process.env.API_URL;.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | Deletes |
|---|---|
| D or d$ | from the cursor to the end of the line, including the character under the cursor |
| C or c$ | the same, then switches to Insert mode so you can type the new ending |
| 2D | to the end of this line and the whole of the next one |
| d0 | from the start of the line up to the cursor (the character under the cursor stays) |
| d^ | back to the first non-blank character, so the indent stays |
| dt; | up to, but not including, the next ; on the line |
| dd | the whole line, wherever the cursor is on it |
| "_D | to the end of the line, without copying it anywhere |
Why D is d$
d is the delete operator and $ is the motion to the end of the line, so d$ reads "delete to the end". It is so common that it has its own key, D. The same pattern runs through Vim: C is c$ (change to the end) and d0 is delete to the start, with 0 the motion to column zero.
Like every delete, D cuts: the text goes into a register, and p pastes it back somewhere else. Use C when you want to replace the end of a line rather than just remove it: it saves you pressing i afterwards, and . repeats the whole change, the new text included, on another line.
The other direction
d0 deletes from the start of the line to the cursor, and d^ stops at the first non-blank character instead, which keeps the indentation in code. Both leave the character under the cursor alone, because a backward motion doesn't include the place it starts from. In Insert mode, Ctrl-u does a similar job: it deletes everything you typed before the cursor on the line.