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.
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.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
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.
export function surgeFee(now: Date) { const busy = ordersInLastHour(now) > 60; return busy ? 2 : 0;}// export function surgeFee(now: Date) {// const busy = ordersInLastHour(now) > 60;// return busy ? 2 : 0;// }// here.Switch it off
surgeFee doesn't ship yet. The cursor is on its first line: gcip.
This exercise needs a keyboard. Read on, and play it at your computer.
Flip it again
The line is already a comment. You press gcc. What does it become?
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
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Half off, half on
The first line is off, the second on. You press gcj over both. What do they become?
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.
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
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
The switch, from memory
Press the keys.
Review comments
Ten lines someone switched off by mistake, in TypeScript, Python and HTML files. Switch each one back on.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.