Learn Practice Daily golf Reference
Ex & substitution·Lesson 5 of 7·7 min·0/8 exercisesPro

:normal on ranges

:normal takes any Normal-mode keys for every line on the slip: :%normal␣A;↵, :g/./normal␣A;↵ to skip the gaps, a highlight with I// , or only the lines :g picks. Then you choose the tool.

Scene

Thursday, 4:30 p.m. The migration script for tonight: every UPDATE statement needs its ;, and a comment line in the middle mustn't get one. The examples file has a block of calls with the old names that should be commented out.

On Monday you handed a recipe card over with :normal @a. A slip can carry the keys themselves.

From memory

Warm-up from earlier chapters

Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.

Delete every line that doesn't mention await.
press the keys…11 keys
1 of 2
Delete every line that doesn't mention await.

Keys as the order

:normal takes any Normal-mode keys, not only a card. :%normal A; presses A ; on every line of the file: each line starts fresh, at its beginning, in Normal mode, and an Insert left open is closed when the line is done. Put any range in front: %, a highlight, or :g/pattern/.

Before
notify(courier)
release(courier)
log(order)
:%normal A;↵
notify(courier);
release(courier);
log(order);
Every line, the keys A ;: a semicolon at the end of each.
Try it

Semicolons everywhere

Lists of statements without their semicolons, every line of each. One slip each: :%normal␣A;↵.

1 of 2Fix the marked spots · 5 left
1log(cart.items);
1log(order.id);
2log(order.total);
3log(zone.fee);
4log(rider.eta);
NORMALLoading the editor…1/20.0s1:1

This exercise needs a keyboard. Read on, and play it at your computer.

Check yourself

Blank lines too

1a
1
2b
NORMAL
Keys pressed: :%normal␣A;↵

You send :%normal␣A;↵ on three lines, the middle one empty. What happens to the empty line?

Pick an answer (or press its number), then watch the engine prove it.
Try it

Not the gaps

This list has blank lines between its groups, and they should stay blank. Every line with something on it gets its ;: :g/./normal␣A;↵.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

On a highlight, or by what they say

Highlight some lines and : gives you '<,'>: :'<,'>normal I// comments out just those. And with :g in front, the keys run only on matching lines: :g/^UPDATE/normal A; gives each UPDATE its semicolon and leaves the comment line alone.

Try it

Comment the examples

The three example lines with the old names get // in front. Highlight them (2j, V, jj) and :normal␣I//␣↵.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Try it

Only the statements

Every UPDATE line gets a ;; the -- comment doesn't. :g/^UPDATE/normal␣A;↵.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Challenge

Your tool

Two jobs, and the tool is yours: a block (Ctrl-v), a card, or :normal on a range or after :g. Before you press anything, say which lines and why that tool. Any route that leaves the right text counts.

Stuck? Show a hint
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

From memory

Keys on many lines, from memory

Press the keys.

Add ; to the end of every line.
scroll here, then press the keys12 keys
1 of 3
Add ; to the end of every line.