278

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.

7 Answers 7

451

(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.

7
  • 1
    Blast, I figured it was something easy, I was thinking some combination of d followed by something. I figured it would be faster to post the question here as well as benefit other people who default to search online before reading the manual.
    – Anthony
    Nov 28, 2011 at 13:34
  • 3
    Or C, the only "real" way to get the cursor at the position indicated, although that puts you in insert mode.
    – Walter
    Nov 28, 2011 at 13:55
  • 1
    @Anthony: There is also a "d followed by something"-equivalent command for D, where "something" is the $ motion: d$.
    – ib.
    Nov 28, 2011 at 14:00
  • 3
    And if you want to end up in insert mode, use C (or c$)
    – Benoit
    Nov 28, 2011 at 14:13
  • 7
    I realize that this solution has already been answered but I was googling for a way to delete an entire line with VIM and found this. The option it turned out that I was looking for was dd from command mode. I hope that helps any others that stumble across this.
    – Frito
    Feb 6, 2014 at 17:01
43

Use D. See docs for further information.

25

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.

11

Execute in command mode d$ .

1
  • 9
    D is a faster solution for this.
    – Sedrik
    Nov 28, 2011 at 13:56
10

Press ESC to first go into command mode. Then Press Shift+D.

https://www.fprintf.net/vimCheatSheet.html

9

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 and registers in general for extra VIM fun!

7

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.