Search, change, inspect, repeat

0 of 1

The technique

Your textVim mode: Normal
Change the two current draft lines and keep the archive. Before: status: draft / next: draft / archive: draft. After: status: ready / next: ready / archive: draft.

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 24

The money helper is called formatMoney now. Rename fmt in the import and in its four calls.

Your textVim mode: Normal

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>
  );
}

Yours

Par

Keyboard shortcuts
Ctrl+Enter
Check the result
Ctrl+Alt+U
Undo the last change
Ctrl+Alt+H
Show the next hint
Ctrl+Alt+R
Start the exercise over
Ctrl+Alt+P
Previous exercise
Ctrl+Alt+N
Next exercise
Ctrl+Alt+K⌃⌥K
Show the keyboard shortcuts
Ctrl+Alt+F⌃⌥F
Turn focus mode on or off
Ctrl+Alt+S⌃⌥S
Open the editor settings
Enter
Go on to the next step after you finish

The Ctrl+Alt shortcuts don't clash with Vim's own keys. On a Mac, use Control and Option.