Search, change, inspect, repeat
The technique
Each . changes the next match. Stop before the archive, because one more would change it too.
Keys in this lesson
- cgn
- Change the next search match. Then . changes the one after.
- n
- Next match.
- .
- Repeat the last change.
Before this lesson: Search reuse and repeatable changes.
More about this lesson
Repeat a change on some search matches and skip the ones that should stay.
Search, make a change, press n to look at the next match, then press the dot only where the same edit belongs. cgn makes finding the match part of the change, so the dot then finds and changes the next match in one go, however far down the file it is. Search for the whole name, because cgn changes only what the search matched. Stop before any match that should stay.
Example
If two current lines and an archive all say pending, change the two current lines and leave the archive. Check each match before you repeat.
Use Start over to try again.
Guides on this topic
Exercise 1 of 1
0keys
par 24The money helper is called formatMoney now. Rename fmt in the import and in its four calls.
Make it look like this
import { formatMoney } from "../lib/money"; // The summary beside the checkout form. It updates as the cart changes. export function OrderSummary({ order, onEdit }) { const hasDiscount = order.discountCents > 0; const freeShipping = order.shippingCents === 0; return ( <aside className="order-summary"> <h2>Your order</h2> <p> {order.lines.length} items, {formatMoney(order.subtotalCents)} </p> <button type="button" onClick={onEdit}> Edit cart </button> {hasDiscount && ( <p className="order-discount"> {order.discountCode}: -{formatMoney(order.discountCents)} </p> )} <p> Shipping: {freeShipping ? "free" : formatMoney(order.shippingCents)} </p> <p className="order-total"> Total {formatMoney(order.totalCents)} </p> </aside> ); }