How to Delete a Line in Vim

The dd command deletes (and cuts) an entire line in one stroke. Combine it with a count to remove several lines at once.

Steps

  1. Delete the current line. In Normal mode, press dd. The line is removed and copied to the register so you can paste it elsewhere.
  2. Delete several lines. Type a number before dd, for example 3dd deletes three lines starting at the cursor.
  3. Delete a single character. Press x to delete the character under the cursor.
  4. Put a deleted line back. Press p to paste the most recently deleted line below the cursor.

In the Vim Browser Editor

These all work in the Vim Browser Editor, and u undoes the last change if you delete something by mistake.

Try it in the editor

Related how-tos

Advertisement