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

Lines

Say the verb twice for the whole line (dd cc yy), D and C for the rest of it, and J joins lines.

Scene

Tuesday, 9:05 a.m. Below the Kitchen class in kitchen.ts is a graveyard: a debug flag left switched on, a setTimeout from the first weekend, comments about 2019, and one statement somebody split across two lines halfway through a thought.

Deleting it word by word would take all morning. The language has a way to say "this whole line".

From memory

Warm-up from earlier chapters

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

Delete from the cursor back to the start of the word.
press the keys…2 keys
1 of 2
Delete from the cursor back to the start of the word.

Say it twice

Say the verb twice and it means the whole line. dd deletes the line the cursor is on, from anywhere on it. cc clears its text and starts typing (you met it as S), and yy copies it. No noun needed: saying the verb twice means the whole line.

Before
kitchen.open();
if (DEBUG) console.log("open");
kitchen.printer.warmUp();
dd
kitchen.open();
kitchen.printer.warmUp();
dd from the middle of the line: the whole line goes, and the lines below move up.
Try it

Clear the graveyard

Each junk line has to go. Get onto it, anywhere, and dd.

1 of 4Delete the line marked red
1export const config = {
1 apiUrl: "https://api.byteburrito.dev",
2 currency: "USD",
3 // TODO: remove before Friday
4 taxRate: 0.0875,
5 openHour: 11,
6 closeHour: 23,
7 slogan: "Code by day, burritos by night",
8};
9// ¯\_(ツ)_/¯
NORMALLoading the editor…1/40.0s1:1

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

D and C: combos to the end

D is a combo like C: d$ ordered as one key. It deletes from the cursor to the end of the line, and C changes to the end, like c$. Perfect for a stale comment trailing after the code.

Before
maxStops: 6, // TODO: ask dispatch
D
maxStops: 6,
D from the space after the comma: the comment and that space go, the code stays.
Try it

Comments about 2019

Three trailing comments. Put the cursor on the space before each // and D.

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.

J joins

Someone split a statement across two lines. J joins the line below onto this one: it drops the second line's indentation and puts one space in its place. gJ joins without adding or removing anything, for the rare case when the space would be wrong.

Check yourself

What does J keep?

1if (rush)
1 cook(next);
NORMAL
Keys pressed: J

You press J on the first line. What do you get?

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

Put it back together

Each split line goes back together with J from anywhere on its first half.

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

Line sentences

From memory.

Delete this whole line.
scroll here, then press the keys2 keys
1 of 5
Delete this whole line.
Challenge

Graveyard shift

Junk lines, split lines and wrong line endings across the codebase. Pick the line sentence that fits each one.

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

Delete the dead

startShift, where the kitchen opens each morning. The DEBUG flag, the setTimeout and the debug log all go, whole lines. The warmUp call somebody split goes back onto one line. And the TODO trailing after return kitchen; goes, but the return stays: the shift needs it. Pick the line sentence that takes exactly that much.

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

Night shift

Endless junk lines and split lines. Delete, join, 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.