Drill 10: Macros & Repeat
Record, play, edit macros. Master the dot command.
Prerequisites
Complete Session 10: Macros & Repeat first.
Practice Text
server1 server2 server3 server4 server5
Drill Exercises
Exercise 1: Dot Repeat
-
daw- delete a word -
w- move to next word -
.- repeat delete -
w.w.w.- continue
Exercise 2: Record Basic Macro
-
qa- start recording to 'a' -
Iprefix_<Esc>j- add prefix, move down -
q- stop recording -
@a- play once -
3@a- play 3 times
Exercise 3: View and Edit Macro
-
:reg a- view macro -
"ap- paste macro as text -
Edit the text
-
0"ay$- yank back to register -
@a- test edited macro
Exercise 4: Macro on Selection
-
Vjj- select lines -
:normal @a- run macro on each line
Exercise 5: Advanced: cgn
-
/pattern- search for something -
cgn- change next match -
Type replacement
-
<Esc>then.- repeat on next match
Self-Assessment
| Skill | Comfortable? |
|---|---|
|
[ ] Yes [ ] Need practice |
|
[ ] Yes [ ] Need practice |
|
[ ] Yes [ ] Need practice |
Edit macro text |
[ ] Yes [ ] Need practice |
|
[ ] Yes [ ] Need practice |