Vim `.` Command


The . command in Vim is incredibly powerful for repeating actions. It re-executes the last change you made, whether it was a complex macro, a simple deletion, or an insertion. This can dramatically speed up your workflow, especially for repetitive tasks.

Here’s a breakdown:

Example Scenario:

Let’s say you have the following text:

apple
banana
orange
grape

You want to change it to:

fruit: apple
fruit: banana
fruit: orange
fruit: grape
  1. Position the cursor at the beginning of the first line.
  2. Type ifruit: <Esc> (insert “fruit: ” at the beginning of the line).
  3. Move the cursor to the next line (using j or the down arrow).
  4. Press .. Vim will repeat the insertion, adding “fruit: ” to the second line.
  5. Repeat steps 3 and 4 for the remaining lines.

This simple example demonstrates the power of the . command. Instead of manually typing “fruit: ” on each line, you efficiently repeat the initial insertion, saving significant time and effort. This principle applies to much more complex edits as well, making the . command an essential tool in any Vim user’s arsenal.