Drill 10: Macros & Repeat

Record, play, edit macros. Master the dot command.

Practice Text

server1
server2
server3
server4
server5

Drill Exercises

Exercise 1: Dot Repeat

  1. daw - delete a word

  2. w - move to next word

  3. . - repeat delete

  4. w.w.w. - continue

Exercise 2: Record Basic Macro

  1. qa - start recording to 'a'

  2. Iprefix_<Esc>j - add prefix, move down

  3. q - stop recording

  4. @a - play once

  5. 3@a - play 3 times

Exercise 3: View and Edit Macro

  1. :reg a - view macro

  2. "ap - paste macro as text

  3. Edit the text

  4. 0"ay$ - yank back to register

  5. @a - test edited macro

Exercise 4: Macro on Selection

  1. Vjj - select lines

  2. :normal @a - run macro on each line

Exercise 5: Advanced: cgn

  1. /pattern - search for something

  2. cgn - change next match

  3. Type replacement

  4. <Esc> then . - repeat on next match

Self-Assessment

Skill Comfortable?

. dot repeat

[ ] Yes [ ] Need practice

qa…​q record

[ ] Yes [ ] Need practice

@a play macro

[ ] Yes [ ] Need practice

Edit macro text

[ ] Yes [ ] Need practice

:normal @a on selection

[ ] Yes [ ] Need practice