Step 2 of 5

4. Basic Editing

Deleting characters

Another thing that we often need to do is delete stuff.

The simplest deletion is getting rid of a single character. In Vim, there are two normal mode mappings that we should be aware of:

  • x, which deletes the character underneath the cursor
  • X, which deletes the character behind the cursor (like backspace)

You can remember this, because x is a cross, and we’re ‘crossing out’ a character.

You can use a count with your command — e.g. 5x — to delete multiple characters at the same time!

Work through the checklist below — practice x and X by removing the extraneous spaces between the words.

  1. Delete the character under the cursor Put the cursor on an extra space and press x in normal mode.
  2. Delete the character behind the cursor This one eats the character before the cursor, like backspace — press X.
  3. Delete three characters with one command Put the cursor on one of the wider runs of spaces and type 3x.
  4. Clean up the rest Keep going with x, X, and counts until only single spaces separate the words.
Delete the character under the cursor Put the cursor on an extra space and press x in normal mode.

Next: Delete the character behind the cursor

Loading editor…