How can I quickly delete a line in VIM starting at the cursor position?
VimVim Problem Overview
I want to be able to delete the remainder of the line I'm on starting at the cursor's position in VIM. Is there an easy command to do this?
To help illustrate, this is before the command.
The quick brown dog jumps over the lazy fox.
^
|----- Cursor is here.
This is after the command
The q
^
|----- Cursor is here.
Vim Solutions
Solution 1 - Vim
(Edited to include commenter's good additions:)
D
or its equivalent d$
will delete the rest of the line and leave you in command mode. C
or c$
will delete the rest of the line and put you in insert mode, and new text will be appended to the line.
This is part of vitutor
and vimtutor
, excellent "reads" for vim beginners.
Solution 2 - Vim
Use D. See docs for further information.
Solution 3 - Vim
You might also be interested in C, it will also delete the end of line like D, but additionally it will put you in Insert mode at the cursor location.
Solution 4 - Vim
Execute in command mode d$
.
Solution 5 - Vim
This is a very old question, but as VIM is still relevant something should be clarified.
Every answer and comment here as of October 2018 has referred to what would commonly be known as a "cut" action, thus using any of them will replace whatever is currently in VIM's unnamed register. This register tends to be treated like a default copy/paste clipboard, so none of these answers will work as desired if you are deleting the rest of a line to paste something in the same place afterward, as whatever was just deleted will be subsequently pasted in place of whatever was yanked before.
The true delete command in the OP's context is "_D
(or "_C
if insert mode is desired) This sends the deleted content into the black hole register, designated by "_
, where it will bother no one ever again (although you can still undo this action using u
).
That being said, whatever was last yanked is stored in the 0 register, and even if it gets replaced in the unnamed register, it can still be pasted using "0p
.
Learn more about [the black hole register][1] and [registers in general][2] for extra VIM fun!
[1]: https://web.archive.org/web/20180324094622/http://blog.dreasgrech.com/2010/06/vims-black-hole-register.html "the black hole register" [2]: https://web.archive.org/web/20180324083047/https://www.brianstorti.com/vim-registers/
Solution 6 - Vim
Press ESC to first go into command mode
. Then Press Shift+D.
Solution 7 - Vim
D
or dd
deletes and copies the line to the register. You can use Vx
which only deletes the line and stays in the normal mode.