Learn Practice Daily golf Reference
Operators·Lesson 5 of 7·7 min·0/8 exercisesPro

Counts everywhere

Say the number: 3dd, d3w (or 3dw), 3p, 5.. Two numbers multiply.

Scene

Tuesday, 4:40 p.m. The nightly report lists what the old code left behind: four debugger lines in a clump here, three console.log calls there, a call with three dead arguments.

You could say dd four times. But a language has numbers, so say it once: delete four lines.

From memory

Warm-up from earlier chapters

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

This line belongs below the next one. Swap them.
press the keys…3 keys
1 of 2
This line belongs below the next one. Swap them.

Say the number

Put a number in the sentence and Vim does it that many times. 3dd deletes three lines. d3w reads delete three words. And 3dw, three times, delete a word, deletes exactly the same three words: put the number wherever it reads best to you.

dw
send(rows, true, false, null, "legacy");
d2w
send(rows, true, false, null, "legacy");
d3W
send(rows, true, false, null, "legacy");
One noun, a growing number. d3W and 3dW would shade exactly the same text.
1debugger;
1debugger;
2debugger;
3const rows = kitchen.tickets.map(format);
NORMALLoading the editor…1:1
Try it

Clumps

Each clump of junk lines goes in one sentence: get onto the first line, count, dd.

1 of 4Fix the marked spots · 2 left
1// delivery zones: where riders go, and what it costs to get there
1console.log("here");
2// TODO: remove before Friday
3export const ZONES = [
4 { name: "Little Havana", lat: 25.7656, lng: -80.219, fee: 2.5 },
5 { name: "Brickell", lat: 25.7663, lng: -80.1917, fee: 2 },
6 { name: "Wynwood", lat: 25.8005, lng: -80.1994, fee: 3 },
7 { name: "Coral Way", lat: 25.7505, lng: -80.2409, fee: 3.5 },
8 { name: "Downtown", lat: 25.7743, lng: -80.1937, fee: 1.5 },
9 { name: "Edgewater", lat: 25.8001, lng: -80.1887, fee: 3 },
10];
11
12export function zoneFor(lat: number, lng: number) {
13 return ZONES.find((z) => Math.abs(z.lat - lat) < 0.01 && Math.abs(z.lng - lng) < 0.01);
14}
15// TODO: remove before Friday
16debugger;
NORMALLoading the editor…1/40.0s1:1

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

Numbers multiply

Two numbers in one sentence multiply. 2d2w reads twice, delete two words: four words. You'll rarely type it on purpose, but it explains a surprise when a count you meant for the noun lands on the verb too.

Check yourself

Count the words

1one two three four five six
NORMAL
Keys pressed: 2d2w

You press 2d2w at the start of the line. What is left?

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

Dead arguments

Three arguments nobody reads. From the t of true, one sentence with a count: d3W treats each name, as one WORD. Or skip the counting and name where to stop: dt" deletes till the quote. Either sentence gets the same result.

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.

Pour and stamp, with a number

Numbers work on the jar and the stamp too. 3p pours the jar three times. And . remembers the count of the change it repeats: after 2dd, each . deletes two more lines.

Before
// -------------------
export function nightlyReport() {}
yy3p
// -------------------
// -------------------
// -------------------
// -------------------
export function nightlyReport() {}
yy fills the jar with the line, 3p pours it three times.

A new number on the stamp

Put a number in front of . and it replaces the old count; it doesn't multiply it. After 2dd, 3. means delete three lines, not delete two lines, three times.

Check yourself

Two, then three

1const a = 1;
1const b = 2;
2const c = 3;
3const d = 4;
4const e = 5;
5const f = 6;
6const g = 7;
NORMAL
Keys pressed: 2dd3.

Seven lines. You press 2dd, then 3.. How many lines are left?

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

Say it with a number

From memory.

Delete this line and the two below it.
scroll here, then press the keys3 keys
1 of 4
Delete this line and the two below it.
Challenge

Bulk trim

Clumps of junk lines and leftovers across the codebase. Say each one once, with a number when it helps.

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.

Boss round

The nightly report

nightlyReport itself. Three console.logs and four debugger lines go, each clump in one sentence, then the three dead arguments in send.

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.

Extra practice optional

The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.

Endless

Bulk trim, all night

Endless clumps and leftovers. Count, then say it once.

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.