Jump by words
w b e hop between words. Their uppercase cousins W B E leap over punctuation.
Day one, 2 p.m. Back from lunch, menu.ts is open again. The menu changes every morning, so you'll be darting around this file all day, and its lines are long.
You could hold l and watch the cursor crawl like a rider stuck in lunch traffic. Or you could move the way you read: a word at a time.
Warm-up from earlier chapters
One from an earlier chapter, from memory, before the new idea. Two wrong tries show the answer.
Words are lily pads
Picture the cursor as a frog and every word as a lily pad. Press w and the frog hops to the start of the next pad. It's the single most useful motion you'll learn today, and frogs have known about it for millions of years.
const order = await placeOrder(cart, user);Hop forward
Reach each green square with w. Five pads, one line.
This exercise needs a keyboard. Read on, and play it at your computer.
Going back
Overshot? b hops back to the start of a word. From the middle of a pad, that's the start of the pad you're on; from its first letter, the start of the one before. The frog can reverse; it just prefers not to talk about it.
Back to which pad?
The cursor is on the d in the middle of placeOrder. You press b. Where does it land?
Back and forth
Targets now appear on both sides of the cursor. Use w and b.
This exercise needs a keyboard. Read on, and play it at your computer.
Land on the end
e lands on the end of a word: the frog on tiptoes at the far edge of the pad. Already on the edge? Then e hops on to the far edge of the next pad. Handy when you want to add something right after a word: a plural s, a closing quote.
const best = reviews.filter(isFiveStar);const best = reviews.filter(isFiveStar);All three
Mix w, b and e. Some targets sit at the end of a word.
This exercise needs a keyboard. Read on, and play it at your computer.
What counts as a word?
To Vim, user.name is three words: user, . and name. Letters, digits and underscores make one kind of word; punctuation makes another. Dots are tiny lily pads, and w stops on every single one.
const city = user.profile.address.city;Predict the landing
You press w three times. Where does the cursor end up?
Counts work here too
Counts aren't just for 5j. 3w is three hops in one breath, and the same trick works with b, e and nearly everything else you'll learn.
Count your hops
The targets are further away now. Count the words and jump in one go: 2w, 3b, 4e.
This exercise needs a keyboard. Read on, and play it at your computer.
WORDs skip the punctuation
Hold Shift and the frog becomes a kangaroo. W, B and E treat anything between spaces as one big WORD, so user.profile.name is a single jump. Reach for them when a line is thick with dots and brackets.
const nearest = riders.sort((a, b) => a.distance - b.distance)[0];const nearest = riders.sort((a, b) => a.distance - b.distance)[0];Leap
Punctuation everywhere. W, B and E get you there in fewer keys.
This exercise needs a keyboard. Read on, and play it at your computer.
The whole family, in one picture
Six keys, two sizes. Each row below is one press from the same cursor, so you can compare them pair by pair. Take a good look: the next block asks you to recall them without the picture.
if (order.status === "late") notify(user.phone, msg);wWbBeEQuick recall
No scrolling up. Read the situation, press the keys.
Code review sprint
Code review: twelve comments scattered across menu.ts, and the reviewer wants answers before the five o'clock merge. Read them first: visit each spot with any word motion you like.
This exercise needs a keyboard. Read on, and play it at your computer.
Answer the review
Every comment says the same thing: typo. Ten of them, each marked in the file. Hop to each one with word motions, then fix it the way you learned this morning: x for a letter too many, i for a missing one, Esc when you're done.
Stuck? Show a hint
Hop with w, e, b (counts help), then x or i… <Esc>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.
Keep hopping
Endless mode. New code every ten targets, longer jumps every five. The frog never gets tired, but you can stop whenever you like.
This exercise needs a keyboard. Read on, and play it at your computer.