Learn Practice Daily golf Reference
Plugins & your editor·Lesson 2 of 4·7 min·0/8 exercisesPro

Commenting

A light switch for lines: gc flips them between code and comment, gcc this line, gcip a paragraph, gc2j three lines; the marker comes from the file's language (TypeScript, Python, HTML), and a mixed range all goes off.

Scene

Monday after launch, 2:00 p.m. The code review comes back: surgeFee is an experiment and mustn't run yet, so switch it off; and the product team wants the 15% tip suggestion back on, with the return 0 that replaced it switched off.

Switching lines off and on is a verb of its own.

From memory

Warm-up from earlier chapters

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

Take the brackets around you off, keeping what's inside.
press the keys…3 keys
1 of 2
Take the brackets around you off, keeping what's inside.

A light switch for lines

gc is a verb that flips lines between code and comment: off, still there to read, and back on. gcc flips the line you're on. Like any verb it takes a noun: gc2j flips this line and the two below, gcip a whole paragraph, such as a function separated by blank lines. On a highlight, gc flips the highlighted lines.

Before
export function surgeFee(now: Date) {
const busy = ordersInLastHour(now) > 60;
return busy ? 2 : 0;
}
gcip
// export function surgeFee(now: Date) {
// const busy = ordersInLastHour(now) > 60;
// return busy ? 2 : 0;
// }
The paragraph, switched off: each line gets the file's comment marker, // here.
Try it

Switch it off

surgeFee doesn't ship yet. The cursor is on its first line: gcip.

Fix the marked spots · 4 left
4export function rushFee(now: Date) {
3 return isLunchRush(now) ? 1 : 0;
2}
1
5export function surgeFee(now: Date) {
1 const busy = ordersInLastHour(now) > 60;
2 return busy ? 2 : 0;
3}
4
5export function tipSuggestion(total: number) {
6 // return Math.round(total * 0.15);
7 // return Math.round(total * 0.18);
8 return 0;
9}
NORMALLoading the editor…0.0s5:1

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

Check yourself

Flip it again

1 // return Math.round(total * 0.15);
NORMAL
Keys pressed: gcc

The line is already a comment. You press gcc. What does it become?

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

Back on, and off

The product team wants the 15% suggestion back on, and the return 0 that replaced it off. The 18% line stays off. The cursor is on the 15% line.

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.

Check yourself

Half off, half on

1 // return Math.round(total * 0.15);
1 return 0;
NORMAL
Keys pressed: gcj

The first line is off, the second on. You press gcj over both. What do they become?

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

The switch knows the language

The marker comes from the file's language: // in TypeScript, # in Python and shell scripts, <!-- --> in HTML. You never type it, so the same gcc works in every file you open.

Try it

Other languages, same switch

Two more from the review. In the Python report, the debug print goes off. In the menu page, Birria is sold out for the day: its line goes off.

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.

From memory

The switch, from memory

Press the keys.

Switch this line off (or back on).
scroll here, then press the keys3 keys
1 of 3
Switch this line off (or back on).
Challenge

Review comments

Ten lines someone switched off by mistake, in TypeScript, Python and HTML files. Switch each one back on.

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.