Step 3 of 5

4. Basic Editing

Deleting lines

Deleting lines is another useful tool to have under your belt. If you are a software engineer, there’s no doubt that you’ll use this one all the time.

Deleting a single line in Vim can be done with the dd command in normal mode. Once again, you can use a count — like 10dd — to delete multiple lines at the same time.

Work through the checklist below to delete all of the lines that start with DELETE ME.

An extra bit for the curious

Try deleting a line, then move your cursor to another line, and hit p (all in normal mode). You’ll notice that the last line you deleted has been inserted on the line below! This is because Vim stores the last deleted line in something called a register. The p command in normal mode is for “putting”/“pasting” the contents of a register.

Using this, see if you can take a line and move it elsewhere.

  1. Delete the first DELETE ME line The cursor starts on it — type dd.
  2. Delete two lines with one command Move down to the next pair of adjacent DELETE ME lines and type 2dd.
  3. Delete the last DELETE ME line Only the KEEP ME lines should survive — move down to the last DELETE ME line and type dd.
Delete the first DELETE ME line The cursor starts on it — type dd.

Next: Delete two lines with one command

Loading editor…