Learn Practice Daily golf Reference
Text objects·Lesson 2 of 8·8 min·0/8 exercisesPro

Words and WORDs

iw and aw are a word and a word in its foil; iW and aW are the kangaroo's WORD, everything between spaces, so ciW replaces a whole dotted path.

Scene

Tuesday, 10:25 a.m. The review on the loader is back: "Too many dotted paths. `data.menu.items` is just `data.menu` now; please shorten them." There are nine across the loader, the kitchen display and the menu page, and you'll rarely have the cursor on the first letter of one.

ciw takes data, or menu, or one dot. You want the whole path, in one bite.

From memory

Warm-up from earlier chapters

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

Delete these brackets and everything in them.
press the keys…3 keys
1 of 2
Delete these brackets and everything in them.

The smallest burrito

You already know the word objects: iw is the word, aw is the word in its foil, the space beside it. ciw renames a word from anywhere inside it; daw deletes it without leaving a double space. The same pair works with any verb: yiw copies the word under the cursor.

The kangaroo’s WORD

Remember the kangaroo from day one? W leaps from space to space, clearing dots and brackets in one go. Its object is the WORD: iW is everything between two spaces, so with the cursor anywhere in data.menu.items, ciW replaces the whole path. aW is the same WORD in its foil, with the space beside it.

iw
return data.menu.items ?? [];
aw
return data.menu.items ?? [];
iW
return data.menu.items ?? [];
aW
return data.menu.items ?? [];
From the same cursor: the word, the word in its foil, the WORD, the WORD in its foil.
1return data.menu.items ?? [];
NORMALLoading the editor…1:20
Try it

One bite

Three dotted paths on the kitchen display to shorten. ciW from anywhere inside each one, and type the short name.

1 of 3Delete the text marked red
1const name = item.details.name ?? "unknown";
1const price = item.details.price ?? 0;
2const late = order.status.isLate && !order.cancelled;
NORMALLoading the editor…1/30.0s1:1

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

Check yourself

Where does the leap end?

1return data.menu.items;
NORMAL
Keys pressed: ciWlistEsc

The cursor is in items. You press ciW, type list, and Esc. What does the line say?

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

Spaced or glued?

The last three paths in menu-page.ts: data.menu.items becomes data.menu, and data.open.hours becomes data.open. Only one of them stands between spaces. Before each one, look at what touches it: ciW where it's spaces on both sides, something else where a bracket, comma or semicolon is stuck to it.

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.

Try it

Dotted names

Dotted names replaced by junk. Put each one back with ciW.

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

Words and WORDs, from memory

Press the keys. The cursor is somewhere inside.

Rename this word.
scroll here, then press the keys3 keys
1 of 5
Rename this word.
Challenge

Small and large

Misspelled words, doubled words and wrong dotted names, ten of them. Word or WORD: pick the size that fits.

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 loader review

10:50. Five comments on menu-loader.ts, top to bottom: three dotted paths lose their last part (data.menu.items becomes data.menu, and so on; the settings one becomes data.currency), a doubled const, and currency, listed twice in the export. Look at what each one touches, then pick word or WORD, inside or around.

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

Words, endlessly

Endless words and WORDs to fix across 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.