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

Search as a motion

A search is a noun: d/ digs from the cursor up to the next match and keeps the match; c/ and y? work the same way.

Scene

Monday, 11:35 a.m. Found it: in delivery.ts, someone pasted a // TEMP: rider override block on Friday, and it swaps the latitude and the longitude of every order it touches, "for testing". It has to go, from the comment down to the end of the block, and the end is below the screen.

You can't see where it ends. The detector can.

From memory

Warm-up from earlier chapters

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

Search backwards for the word under the cursor.
press the keys…
1 of 2
Search backwards for the word under the cursor.

Dig to the beep

A search is a noun like any motion. d/ reads delete up to the next match of what I type: dig from where you stand to the next beep. The match itself stays in the ground: the search stops just before it, so d/nearest↵ deletes everything up to nearest and keeps nearest.

/nearest↵
assign(order, legacy, oldRider, nearest);
t)
assign(order, legacy, oldRider, nearest);
d/nearest↵ digs up to nearest; dt) to the bracket. The search keeps what it found.

Whole blocks

Because the match stays, you can cut a whole block of lines and keep the indentation: start on the block's first line, and search for the start of the line after the block. Everything in between goes, and the next line moves up into its place.

Try it

Dig out the override

The cursor goes to the // of the TEMP comment, then d/ up to the start of const stop (const s is enough). Then the three leftover arguments at the end of directions(…) go with d/)↵.

1 of 2Fix the marked spots · 5 left
1export function routeFor(order: Order, rider: Rider) {
1 // TEMP: rider override (Friday)
2 const lat = order.address.lng;
3 const lng = order.address.lat;
4 order.address = { ...order.address, lat, lng };
5 log("override", lat, lng);
6 const stop = { lat: order.address.lat, lng: order.address.lng };
7 return directions(rider.position, stop, legacyOptions, oldRider, true);
8}
NORMALLoading the editor…1/20.0s1:1

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

Check yourself

What stays in the ground?

1assign(order, legacy, oldRider, nearest);
NORMAL
Keys pressed: d/nearest↵

The cursor is on legacy. You press d/, type nearest, and ↵. What is left?

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

Change and copy

Any verb takes the noun. c/ digs up to the beep and starts Insert mode, for replacing a stretch of text you can't see the end of. y? copies back up to an earlier match, ready to pour out with p.

Try it

When nothing beeps

One more TEMP block, in quote. Your notes say it ends before const sum. From the //, type d/ and const sum and watch the highlight: at the s it goes dark, because nothing matches. Don't dig blind: Esc cancels, and nothing is deleted. (Pressing ↵ would delete nothing either; Vim just says Pattern not found.) Then dig to the line that is really there.

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

Dig, from memory

Press the keys.

Delete from here up to the next order.
scroll here, then press the keys8 keys
1 of 3
Delete from here up to the next order.
Boss round

Three pasted blocks

dispatch has three // TEMP blocks from Friday. Each ends right before a line that stays: const, if and return. From each //, dig up to the line that stays.

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.

Challenge

Leftovers, anywhere

Ten leftovers and wrong values across the codebase. Any verb, any noun, searches included.

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.