Vim course Lesson 4 of 6

Vim from zero: the dot command repeats the change

The dot command repeats the last change. cwadd turns the word under the cursor into add. Dot on the next order line does it again.

Zoe is one of GoByte's characters. This post was drafted by AI agents in Zoe's voice, then fact checked, run and edited by the GoByte team.

Back to top

The dot command, ., repeats the last change. It does not repeat a motion you did afterward. It repeats the edit. Change the first word of an order once, move to the next order, and press ..

Dot repeats the change, not the motion#

. repeats the last change. It does not repeat the motions you used to get there. cw deletes the word under the cursor and enters insert. Typing add and leaving insert mode is the change. On the first line, item becomes add. You then move to the next item yourself, and . runs the same change there. A motion between the two edits is not part of what dot stores. An accidental insert after the real change becomes the new last change. u undoes it.

The same change, aimed at the next order
  1. cwaddadd latte = "oat"
  2. dotadd muffin = "warm"
0cwadd<Esc>
j0.
add latte = "oat"
add muffin = "warm"

One change, then dot#

Start from two lines, cursor on the first:

item latte = "oat"
item muffin = "warm"

0 lands on the first character. cw deletes item and enters insert mode. Type add. Press Escape. The first line is add latte = "oat". j0 moves to the start of the muffin line, and . repeats the change. The second line is add muffin = "warm".

The sample shows the keys and the two lines after the dot has been used. The motion between them is not part of the change, which is why you can aim the cursor before you repeat. If you insert a character by accident after the change, that insert becomes the new last change, and . repeats the accident. Undo with u, then do the real change again.

n jumps to the next search match. . then applies the change there. The pair n. is how you walk a file applying one edit. The search is yours to confirm. Dot will happily change the wrong match if you land on it. Look once, then press the dot. The next lesson stores the quoted note so you can put it on another line.

Report a mistake

Your product here? Partner with us

Back to top

Discussion

No comments yet. Signed in GoByte members with a verified e-mail can join. Community guidelines

Reading is open to everyone. Commenting and voting need a GoByte account with a verified e-mail.