Kurt Keller's Blog

tech notes and more

repeat

Time and time again people need to make the same single change in a document in multiple places. I often see people replacing things over and over again with dw i <type new word> <ESC>, spending a lot of time and making typing mistakes in the process. There is a very handy command to repeat the last change at the current position of the cursor: . Yes, just a single dot. Lots of time saved and no typing mistakes. This is one of the most worthwhile commands to remember!

. repeat the last change at the current position

Let’s walk through an example. In the list on the left below, after you went shopping, you want to change o todo into x done on all the items you bought so it looks like the list on the right.

before after
o todo: call mommy
o todo: buy milk
o todo: post letters
o todo: buy meat
o todo: buy vegetables
o todo: checkup for car
o todo: call mommy
x done: buy milk
o todo: post letters
o todo: buy meat
x done: buy vegetables
o todo: checkup for car
  1. go to the first position where something needs to be changed
  2. type R to enter overwrite mode
  3. type x done to change the text
  4. ESC to exit overwrite mode
  5. move to the next position where you need to make the same change
  6. type . (a single dot) to repeat the change at this position



This can also be (and often is) combined with some search command. So if your list is much longer, you might prefer the following:

  1. type 1G to move to the first line of the document
  2. type /buy followed by ENTER to search for the string buy
  3. type 0 to move to the start of the current line
  4. type 2cw followed by x done followed by ESC to change the first two words
  5. type jn to move to the next line and search for the next occurrence of the string buy
  6. because you did not buy meat type n again to search for the next occurrence of the string buy
  7. move to the start of the current line by typing 0
  8. repeat the last change by typing . (a single dot)
Share

Leave a Reply