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

Delete & change words

Word-sized sentences: dw takes the space, de doesn't, db reaches back; cw is the idiom; daw and ciw work from anywhere in the word.

Scene

Monday, 1:30 p.m. Further into kitchen.ts the variable names tell the history of the company: ordr from the first weekend, theOrderObjectNew from the consultant, q2 from someone in a hurry. Most of the rewrite is deleting and changing words.

The language has a few word-sized sentences, and one idiom you'll be glad of.

From memory

Warm-up from earlier chapters

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

Copy to the end of the line.
press the keys…2 keys
1 of 2
Copy to the end of the line.

To the next word, or to its end

dw reads delete to the next word, so from the start of a word it takes the word and the space after it: the right sentence when the whole word should go. de reads delete to the end of the word and stops at its last letter, so the space stays. And db reads delete back to the start of the word: from the middle of waitMinutes, it takes wait.

w
const total = await sumPrices(order.items);
e
const total = await sumPrices(order.items);
b
const total = await sumPrices(order.items);
From the middle of await: w takes the rest of the word and its space, e stops at its last letter, b reaches back to its start.
1const next = await await this.queue.shift();
NORMALLoading the editor…1:20
Try it

Space or no space

Two trims. A doubled await has to go with its space: dw. Then waitMinutes becomes wait, keeping the space before the =: put the cursor on the M and de.

1 of 2Delete the text marked red
1const next = await await this.queue.shift();
1const waitMinutes = estimate(next.items);
2log("cooking", next.id);
NORMALLoading the editor…1/20.0s1:1

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

cw, the idiom

Every language has idioms: phrases that don't mean exactly what their words say. cw is Vim's. By the rule it would take the space after the word too, but Vim reads it as change word, and a word doesn't include the space after it, so it stops at the end of the word. That's what you want when renaming: cw and the new name is the everyday rename.

Check yourself

Literal or idiom?

1const ordr = q2.shift();
NORMAL
Keys pressed: cworderEsc

The cursor is on the o of ordr. You press cw, type order, and Esc. What does the line say?

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

The first weekend

ordr is from the first weekend, and it appears three times. Rename the first with cw from the start of the word, then slide to the start of each of the others and stamp it with .: a rename isn't done until every copy matches.

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.

A word, or the inner word

Two more nouns read like plain words. aw is a word: the word plus the space after it (or before it, if nothing follows), so daw deletes it cleanly from anywhere inside it. iw is inner word: just the letters, so ciw renames a word with the cursor anywhere in it: the spellcheck recipe from last week, and now you can read it. These nouns only work after a verb: on their own, a and i still start Insert mode. Track 6 is all about nouns like them.

aw
return format(oldOrderTicket ?? ordr);
iw
return format(oldOrderTicket ?? ordr);
From the middle of the word: aw takes it and the space after it, iw takes only the letters.
Try it

Three eras

Misspelled names to fix with ciw, and doubled words to lose with daw. Neither needs you at the start of the word.

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

Word sentences

From memory.

Delete to the end of this word, keeping the space after it.
scroll here, then press the keys2 keys
1 of 5
Delete to the end of this word, keeping the space after it.
Challenge

Rename the ancients

Ten names and leftovers from every era of Byte Burrito. Rename, delete, trim: one sentence each.

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 Kitchen class

The heart of kitchen.ts: the Kitchen class. Five fixes before anyone else opens this file: two doubled words lose their extra copy, lastOrderObjectNew becomes lastOrder, and two misspelled names get the spelling the rest of the class uses (order, next).

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

Name patrol

Endless misspellings and doubled words, all over the codebase.

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.