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

Operators speak a language

Commands are sentences: a verb (d delete, c change, y yank) and a noun, which is any motion you know. dw, ct,, d$.

Scene

Monday, 9:10 a.m. Since Friday's happy hour the kitchen display has shown every ticket three times. The code behind it is kitchen.ts, the oldest file in the repo, and it reads like it was written during a lunch rush: leftover arguments, dead flags, half-finished renames.

This week you rewrite it. That means cutting, a lot, and so far you can only cut one character at a time, or change the rest of a line.

From memory

Warm-up from earlier chapters

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

Take back the last change.
press the keys…
1 of 2
Take back the last change.

Verb, then noun

Vim's commands are a tiny language. d is a verb: delete. Every motion you know is a noun: w is to the next word, $ is to the end of the line. Put them together and you have a sentence: dw, delete to the next word.

w
const next = this.queue.shift();
e
const next = this.queue.shift();
t=
const next = this.queue.shift();
$
const next = this.queue.shift();
Same verb, four nouns, one cursor. The shaded text is what d deletes with each one.
1cook(order, { rush: true }, "kitchen-2");
NORMALLoading the editor…1:6

Every motion is a noun

f, t, b, e, W, 0, ^: every motion from track 1 is a noun now. After d, Vim waits for one, and the grammar bar reads your sentence back in words as you type it (you can switch it off in Settings). dt, reads delete till the comma; a count travels with its noun, so d2w is delete to the second word.

Try it

Cut the leftovers

Each green-boxed spot starts a leftover from an old rewrite. Get there, then say it in one sentence: d plus the motion that covers exactly the leftover.

1 of 4Delete the text marked red
1export class Kitchen {
1 private queue: Order[] = [];
2 private busy = false;
3
4 enqueue(order: Order) {
5 this.queue.push(void order);
6 this.startNext();
7 }
8
9 startNext() {
10 if (this.busy || this.queue.length === 0) return;
11 this.busy = true;
12 const next = debugger, this.queue.shift();
13 cook(next).then(() => this.finish());
14 }
15}
NORMALLoading the editor…1/40.0s1:1

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

Check yourself

Read the sentence

1assign(order, nearest, { rush: true }, eta);
NORMAL
Keys pressed: d2f,

The cursor is on the o of order. You press d2f,. What is left?

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

Change your mind

1const next = queue.shift();
NORMAL
Keys pressed: dEscw

You press d, then think better of it and press Esc. Then you press w. What happens?

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

c: delete, then type

c is the verb change: it deletes what the noun covers and starts Insert mode, so one sentence takes out the wrong text and lets you type the right one. ct, changes everything up to the next comma; c$ changes to the end of the line (you met it as C). The spellcheck recipes were this verb all along: ciw is c with the noun inner word, and cgn is c with the next match.

Before
const url = "http://localhost:3000";
ct;process.env.API_URLEsc
const url = process.env.API_URL;
ct; reads change till the semicolon. Then type the new value.
Try it

Say it right

Something between the brackets, commas or quotes is wrong. Start at the wrong part, c plus the motion that reaches its end, and type the right text.

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.

y: copy

The third verb is y, yank: Vim's word for copy. It takes the same nouns (yw, y$, yt)) and changes nothing you can see. Where the copy goes, and how to put it back with p, is three lessons away.

From memory

Say the sentence

From memory: verb, then noun.

Delete to the end of the line.
scroll here, then press the keys2 keys
1 of 5
Delete to the end of the line.
Challenge

Trim the kitchen

Leftovers to cut and wrong values to change all over the codebase. One sentence each: the verb, then the noun that covers it exactly.

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

Three of every ticket

Found it: showTicket in kitchen.ts, with copies = 3. That 3 should be a 1. Then four leftovers, one sentence each: the legacy flag and the oldFormat argument go, the log message should say "ticket", and debugInfo(order) leaves the log call. Pick the noun that covers exactly what has to go.

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.

One order, one ticketFinish the exercise above to see it.

Extra practice optional

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

Endless

Ticket queue

Endless leftovers and wrong values. Verb, noun, next.

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.