Vim Recipes ‣ Basics ‣ Deleting Text
You wish to remove some text from a file. For example, you've typed a paragraph which is no longer needed.
In Normal mode, move your cursor over the character to banish and hit x (mnemonic: expunge). This deletes characters under and after the cursor; to delete characters before the cursor use X. This is fine for single characters, but to delete words and other text objects you can use dmotion. The difference, then, is that x deletes characters, whereas d deletes text described by a given motion.
If you'd rather nuke entire lines at a time use dd. So, to delete the current line and the one following it: 2dd. Use a range prefix to delete the specified lines, e.g. :17,20d deletes lines seventeen through to twenty.
A compromise is to delete the remainder of a line, which can be achieved with D. If your cursor was positioned after compromise in the above sentence, and you then hit D, the line would be changed to just A compromise.
If you've selected a block of text visually, you can delete it all with x.
Vim doesn't just delete text; it saves it to a register first. If you delete a small amount of text (less than a line), it's stored in a register named "-. Otherwise, it's stored in "0, whose existing contents are moved to "1, whose existing…right up to "9. This allows you easy access to previously deleted text inasmuch as you can recall, say, the 3rd most recently deleted line with "2p. Even more usefully, you can use :registers to view your recent deletions. The Undoing Mistakes recipe explains how to revert these deletions.