The Power of Repetition

If Vim had a mascot, it would be the Dot Command (.).

The Dot Command simply does one thing: It repeats the last change.

This sounds trivial, but it changes everything. It turns editing into a game of golf: “How can I perform this edit in a way that the Dot Command can repeat it for me?”

⚡ What is a “Change”?

A “change” is any command that modifies the buffer.

  • dw (Delete word) → Change
  • iHello<Esc> (Insert “Hello”) → Change
  • dd (Delete line) → Change
  • x (Delete character) → Change
  • w (Move forward) → Not a change (Motion)
  • y (Yank) → Not a change (Does not modify buffer)

1. The Ideal Edit

To maximize the power of ., you need to compose edits that are repeatable.

The Wrong Way

You want to append a semicolon ; to the end of the line.

  1. $ (Move to end)
  2. a (Append)
  3. ; (Type semicolon)
  4. <Esc> (Exit)

If you move to the next line and press ., what happens? It just types ;. It does not move to the end of the line, because $ was a motion, not part of the change.

The Right Way

  1. A (Append at End of Line)
  2. ; (Type semicolon)
  3. <Esc> (Exit)

Now, A is the operator (well, technically a command that implies motion+insert). If you move to the next line and press ., it jumps to the end and adds the semicolon.

Tip

Always prefer commands that combine motion and action (I, A, C, s) over moving manually and then editing. They bundle the intent into a single repeatable unit.


2. The Dot Formula

The classic pattern for repetitive edits is:

Move + Dot

  1. Perform the first edit carefully.
  2. Move to the next target.
  3. Press ..
  4. Repeat steps 2-3.

Example: Deleting specific lines

Content:

Item 1
DELETED
Item 2
DELETED
Item 3
  1. Move to first “DELETED”.
  2. Type dd (delete line).
  3. Move to next “DELETED” (j or /DELETED).
  4. Press ..

3. Case Study: Refactoring a List

Imagine you have this raw data:

apple
banana
cherry
date

You want to turn it into a JavaScript array:

"apple",
"banana",
"cherry",
"date",

Strategy

We need to:

  1. Quote the word.
  2. Add a comma.

Step 1: The First Edit

  • ^ (Start of line) → Motion (ignored by dot)
  • I (Insert at start) → Start Change
  • "Type quote
  • <Esc>End Change

Wait, that only adds the first quote. We want to do it all in one go.

Better Strategy: A and I are separate changes. We can’t do both in one dot command unless we use a macro or a smarter change.

The “Change Inner Word” Strategy:

  1. ciw (Change Inner Word)
  2. "apple", (Retype the word with quotes - wait, that’s slow)

The Surround Strategy (Native Vim):

  1. I" (Insert quote at start) → <Esc>
  2. A", (Append quote comma at end) → <Esc>

This requires two dot commands. One for the start, one for the end.

  1. I"<Esc>
  2. j.j.j. (Apply to all)
  3. A",<Esc>
  4. j.j.j. (Apply to all)

This is still very fast.


4. Interactive Refactoring Challenge

Can you clean up this data using the Dot Command strategy?

Goal: Convert the list of names into a JSON-like format: name: "Value",

The Dot Repeater

Your Editor (Active Line Highlighted)
Controls
State: Normal Mode | Last Change: None