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

* # g* g#

Aim the detector at your feet: * and # search for the word under the cursor, whole words only; g* and g# match it inside longer words too.

Scene

Monday, 10:10 a.m. Every file that touches a coordinate uses the same few names: lat, lng, zone. You've typed /lat five times this morning, each time with the cursor already sitting on the word lat.

Why tune the detector by hand when you can aim it at the coin under your feet?

From memory

Warm-up from earlier chapters

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

Search forward for order.
press the keys…7 keys
1 of 2
Search forward for order.

More like this

You met * in week one, sliding along the packing line; on this beach it aims the detector at your feet. It reads the word under the cursor and searches for more like it, no typing. * sweeps forward, down the file; # sweeps backwards, up it. After either one, n and N carry on with the same word.

2// delivery zones: where riders go, and what it costs to get there
1export const ZONES = [
3 { name: "Little Havana", lat: 25.7656, lng: -80.219, fee: 2.5 },
1 { name: "Brickell", lat: 25.7663, lng: -80.1917, fee: 2 },
2 { name: "Wynwood", lat: 25.8005, lng: -80.1994, fee: 3 },
3 { name: "Coral Way", lat: 25.7505, lng: -80.2409, fee: 3.5 },
4 { name: "Downtown", lat: 25.7743, lng: -80.1937, fee: 1.5 },
5 { name: "Edgewater", lat: 25.8001, lng: -80.1887, fee: 3 },
6];
7
8export function zoneFor(lat: number, lng: number) {
9 return ZONES.find((z) => Math.abs(z.lat - lat) < 0.01 && Math.abs(z.lng - lng) < 0.01);
10}
NORMALLoading the editor…3:28

Exactly that word, or anything like it

* is strict: it finds lat as a whole word, so zone.lat beeps and latitude doesn't. Sometimes you want the looser setting: g* and g# search for the same letters anywhere, inside longer words too.

*n
lat = zone.lat ?? latitude ?? lat;
2 keys
g*n
lat = zone.lat ?? latitude ?? lat;
4 keys
From the first lat: * stops only at the word lat; g* stops inside latitude too.
Check yourself

Which ones beep?

1lat
1latitude
2zone.lat
NORMAL
Keys pressed: *

The cursor is on lat in line 1. You press *. Where does it land?

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

The near miss

1const lat = 25.8;
1const flatFee = 2;
2return { lat };
NORMAL
Keys pressed: g*

The cursor is on lat in line 1. You press g*. Where does it stop?

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

Aim at your feet

Targets are copies of words near the cursor. Move onto one copy, then * or # and n to reach the target.

1 of 6Move the cursor onto the
1export function happyHour(item: Item, hour: number) {
1 const base = item.price * item.qty;
2 const off = hour >= 17 && hour < 19 ? base * 0.2 : 0;
3 const tax = (base - off) * TAX_RATE;
4 const total = base - off + tax + item.tip;
5 log("happy hour", item.id, base, off, total);
6 return Math.round(total * 100) / 100;
7}
8
9export const LIMITS = { maxQty: 12, maxTip: 20, rushMinutes: 45 };
NORMALLoading the editor…1/60.0s1:1

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

Try it

Strict or loose

A rider function where lat also hides inside latitude and flatFee. Each goal says which kind of match you want: strict (*) for the word itself, loose (g*) when it may sit inside a longer name. Pick the one that gets there in the fewest presses.

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

More like this, from memory

Press the keys.

Search forward for the word under the cursor.
scroll here, then press the keys
1 of 4
Search forward for the word under the cursor.
Challenge

More like this

Twelve targets that are copies of words elsewhere in the file. Aim at a copy, sweep, step.

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

Every lat

The first eight lats in zones.ts, top to bottom. Get onto the first, then let * and n walk you through the rest.

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.

Every lat, accounted forFinish the exercise above to see it.

Extra practice optional

The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.

Endless

Echoes

Endless copies to find.

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.