{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.16","languages":{"javascript":{"id":"intermediate.16","title":"Checkpoint: repeat a change across a file","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"The API takes the order's id now. Rename <code>oid</code> to <code>orderId</code> everywhere, send <code>PATCH</code> instead of <code>PUT</code> in both requests, and delete the comment about page size, which the API no longer has. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"jsx","start":"import { request } from \"./client\";\n\n// Twenty orders a page. Ask for the next page until it comes back empty.\nexport function listOrders(page = 1) {\n  return request(`/orders?page=${page}`);\n}\n\nexport function getOrder(oid) {\n  return request(`/orders/${oid}`);\n}\n\nexport function renameOrder(oid, name) {\n  return request(`/orders/${oid}`, { method: \"PUT\", body: { name } });\n}\n\nexport function setDeliveryNote(oid, note) {\n  return request(`/orders/${oid}/delivery`, { method: \"PUT\", body: { note } });\n}","startCursor":{"line":0,"ch":0},"paths":[{"keys":["2","j","d","d","/","oid","<CR>","c","g","n","orderId","<Esc>",".",".",".",".",".","/","PU","<CR>","c","w","PATCH","<Esc>","n","."],"tier":"idiomatic","technique":"motion:gn","core":["motion:gn","dot","linewise"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { request } from \"./client\";\n\nexport function listOrders(page = 1) {\n  return request(`/orders?page=${page}`);\n}\n\nexport function getOrder(orderId) {\n  return request(`/orders/${orderId}`);\n}\n\nexport function renameOrder(orderId, name) {\n  return request(`/orders/${orderId}`, { method: \"PATCH\", body: { name } });\n}\n\nexport function setDeliveryNote(orderId, note) {\n  return request(`/orders/${orderId}/delivery`, { method: \"PATCH\", body: { note } });\n}","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.16#0","canonicalFingerprint":"9i3lf8"},{"task":"Translate the four headings: wrap each one's text in <code>{t(…)}</code>, as the page title is. Also make the delete button <code>danger</code> instead of <code>secondary</code>. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"jsx","start":"import { useTranslation } from \"react-i18next\";\nimport { AddressForm, NewsletterToggle } from \"./account\";\n\nexport function AccountPage({ customer, onDelete }) {\n  const { t } = useTranslation();\n  return (\n    <main className=\"account\">\n      <title>{t(\"Your account\")}</title>\n      <h2>Contact details</h2>\n      <p>{customer.email}</p>\n      <h2>Delivery address</h2>\n      <AddressForm value={customer.address} />\n      <h2>Newsletter</h2>\n      <NewsletterToggle customer={customer} />\n      <h2>Delete account</h2>\n      <button className=\"secondary\" onClick={onDelete}>Delete my account</button>\n    </main>\n  );\n}","startCursor":{"line":4,"ch":2},"paths":[{"keys":["4","j","q","a","f",">","a","{t(\"","<Esc>","f","<","i","\")}","<Esc>","2","j","0","q","@","a","@","@","@","@","k","c","i","\"","danger","<Esc>"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay","textobject:i\""],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { useTranslation } from \"react-i18next\";\nimport { AddressForm, NewsletterToggle } from \"./account\";\n\nexport function AccountPage({ customer, onDelete }) {\n  const { t } = useTranslation();\n  return (\n    <main className=\"account\">\n      <title>{t(\"Your account\")}</title>\n      <h2>{t(\"Contact details\")}</h2>\n      <p>{customer.email}</p>\n      <h2>{t(\"Delivery address\")}</h2>\n      <AddressForm value={customer.address} />\n      <h2>{t(\"Newsletter\")}</h2>\n      <NewsletterToggle customer={customer} />\n      <h2>{t(\"Delete account\")}</h2>\n      <button className=\"danger\" onClick={onDelete}>Delete my account</button>\n    </main>\n  );\n}","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.16#1","canonicalFingerprint":"apygjo"},{"task":"The two tests that call Stripe's real API fail on CI. Skip them with <code>it.skip</code>, and give the client a <code>10_000</code> ms timeout instead of <code>2000</code>. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"jsx","start":"import { createPaymentIntent, refund } from \"./stripe\";\nimport { client } from \"./client\";\n\nconst stripe = client({ apiKey: process.env.STRIPE_TEST_KEY, timeout: 2000 });\n\nit(\"creates an intent in cents\", async () => {\n  const intent = await createPaymentIntent(stripe, { amount: 1250 });\n  expect(intent.amount).toBe(1250);\n});\n\nit(\"refunds a captured payment\", async () => {\n  const done = await refund(stripe, \"pi_test_captured\");\n  expect(done.status).toBe(\"succeeded\");\n});\n\nit(\"rejects a negative amount\", () => {\n  expect(() => createPaymentIntent(stripe, { amount: -1 })).toThrow();\n});","startCursor":{"line":1,"ch":0},"paths":[{"keys":["6","G","w","i",".skip","<Esc>","}","j","w",".","/","20","<CR>","c","w","10_000","<Esc>"],"tier":"idiomatic","technique":"dot","core":["dot","door-i","search:/"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { createPaymentIntent, refund } from \"./stripe\";\nimport { client } from \"./client\";\n\nconst stripe = client({ apiKey: process.env.STRIPE_TEST_KEY, timeout: 10_000 });\n\nit.skip(\"creates an intent in cents\", async () => {\n  const intent = await createPaymentIntent(stripe, { amount: 1250 });\n  expect(intent.amount).toBe(1250);\n});\n\nit.skip(\"refunds a captured payment\", async () => {\n  const done = await refund(stripe, \"pi_test_captured\");\n  expect(done.status).toBe(\"succeeded\");\n});\n\nit(\"rejects a negative amount\", () => {\n  expect(() => createPaymentIntent(stripe, { amount: -1 })).toThrow();\n});","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.16#2","canonicalFingerprint":"36d4kp"}]},"python":{"id":"intermediate.16","title":"Checkpoint: repeat a change across a file","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"The API takes the order's id now. Rename <code>oid</code> to <code>order_id</code> everywhere, send <code>PATCH</code> instead of <code>PUT</code> in both requests, and delete the comment about page size, which the API no longer has. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"python","start":"from .client import request\n\n# Twenty orders a page. Ask for the next page until it comes back empty.\ndef list_orders(page=1):\n    return request(\"GET\", f\"/orders?page={page}\")\n\n\ndef get_order(oid):\n    return request(\"GET\", f\"/orders/{oid}\")\n\n\ndef rename_order(oid, name):\n    return request(\"PUT\", f\"/orders/{oid}\", json={\"name\": name})\n\n\ndef set_delivery_note(oid, note):\n    return request(\"PUT\", f\"/orders/{oid}/delivery\", json={\"note\": note})","startCursor":{"line":0,"ch":0},"paths":[{"keys":["2","j","d","d","/","oid","<CR>","c","g","n","order_id","<Esc>",".",".",".",".",".","/","PU","<CR>","c","w","PATCH","<Esc>","n","."],"tier":"idiomatic","technique":"motion:gn","core":["motion:gn","dot","linewise"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"from .client import request\n\ndef list_orders(page=1):\n    return request(\"GET\", f\"/orders?page={page}\")\n\n\ndef get_order(order_id):\n    return request(\"GET\", f\"/orders/{order_id}\")\n\n\ndef rename_order(order_id, name):\n    return request(\"PATCH\", f\"/orders/{order_id}\", json={\"name\": name})\n\n\ndef set_delivery_note(order_id, note):\n    return request(\"PATCH\", f\"/orders/{order_id}/delivery\", json={\"note\": note})","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.16#0","canonicalFingerprint":"9i3lf8"},{"task":"Translate the four labels: wrap each one in <code>_(…)</code>, as the model's own name is. Also make the default status <code>new</code> instead of <code>draft</code>. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"python","start":"from django.db import models\nfrom django.utils.translation import gettext_lazy as _\n\n\nclass Order(models.Model):\n    number = models.CharField(verbose_name=\"Order number\", max_length=20, unique=True)\n    email = models.EmailField(verbose_name=\"Email address\")\n    total = models.DecimalField(verbose_name=\"Total\", max_digits=10, decimal_places=2)\n    placed_at = models.DateTimeField(verbose_name=\"Placed at\", auto_now_add=True)\n    status = models.CharField(max_length=20, default=\"draft\")\n\n    class Meta:\n        verbose_name = _(\"order\")\n        ordering = [\"-placed_at\"]","startCursor":{"line":4,"ch":0},"paths":[{"keys":["j","q","a","f","\"","i","_(","<Esc>","2","f","\"","a",")","<Esc>","j","0","q","@","a","@","@","@","@","c","i","\"","new","<Esc>"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay","textobject:i\""],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"from django.db import models\nfrom django.utils.translation import gettext_lazy as _\n\n\nclass Order(models.Model):\n    number = models.CharField(verbose_name=_(\"Order number\"), max_length=20, unique=True)\n    email = models.EmailField(verbose_name=_(\"Email address\"))\n    total = models.DecimalField(verbose_name=_(\"Total\"), max_digits=10, decimal_places=2)\n    placed_at = models.DateTimeField(verbose_name=_(\"Placed at\"), auto_now_add=True)\n    status = models.CharField(max_length=20, default=\"new\")\n\n    class Meta:\n        verbose_name = _(\"order\")\n        ordering = [\"-placed_at\"]","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.16#1","canonicalFingerprint":"apygjo"},{"task":"The log lines print <code>{order.number}</code> as it's written. Make the three messages f-strings, and log the refund one as a <code>warning</code> instead of <code>info</code>. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"python","start":"import structlog\n\nlog = structlog.get_logger()\n\n\ndef payment_succeeded(order):\n    order.mark_paid()\n    log.info(\"Paid order {order.number}\")\n\n\ndef payment_failed(order, reason):\n    order.mark_failed(reason)\n    log.error(\"Payment failed for {order.number}: {reason}\")\n\n\ndef refund_created(order, amount):\n    order.add_refund(amount)\n    log.info(\"Refunded {amount} on {order.number}\")","startCursor":{"line":2,"ch":0},"paths":[{"keys":["/","(\"","<CR>","a","f","<Esc>","n",".","n",".","b","b","c","w","warning","<Esc>"],"tier":"idiomatic","technique":"dot","core":["dot","search:n","door-a"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import structlog\n\nlog = structlog.get_logger()\n\n\ndef payment_succeeded(order):\n    order.mark_paid()\n    log.info(f\"Paid order {order.number}\")\n\n\ndef payment_failed(order, reason):\n    order.mark_failed(reason)\n    log.error(f\"Payment failed for {order.number}: {reason}\")\n\n\ndef refund_created(order, amount):\n    order.add_refund(amount)\n    log.warning(f\"Refunded {amount} on {order.number}\")","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.16#2","canonicalFingerprint":"36d4kp"}]},"text":{"id":"intermediate.16","title":"Checkpoint: repeat a change across a file","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"The warehouse calls it a product code now. Change all five <code>SKU</code> to <code>product code</code>. Prices are required in the file now, so delete the line about leaving them empty, and the page is called Catalog, not Products. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"text/plain","start":"# Importing products\n\nThe import reads a CSV export from the warehouse system, one row per SKU.\n\n## Columns\nThe first column is the SKU, then the name, the price in cents and the stock.\nLeave the price empty to use the one the shop has now.\nRows with an unknown SKU are added as new products, hidden until someone checks them.\n\n## Running it\nUpload the file on the Products page and press Import.\nIt usually takes under a minute for a few thousand rows.\n\n## When a row fails\nThe report lists each failed row with its SKU and the reason.\nFix the rows in the CSV and upload just those again.\nA SKU that appears twice in one file is imported once, from its last row.","startCursor":{"line":0,"ch":0},"paths":[{"keys":["6","j","d","d","/","SKU","<CR>","c","g","n","product code","<Esc>",".",".",".",".","4","j","F","P","c","w","Catalog","<Esc>"],"tier":"idiomatic","technique":"motion:gn","core":["motion:gn","dot","linewise"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Importing products\n\nThe import reads a CSV export from the warehouse system, one row per product code.\n\n## Columns\nThe first column is the product code, then the name, the price in cents and the stock.\nRows with an unknown product code are added as new products, hidden until someone checks them.\n\n## Running it\nUpload the file on the Catalog page and press Import.\nIt usually takes under a minute for a few thousand rows.\n\n## When a row fails\nThe report lists each failed row with its product code and the reason.\nFix the rows in the CSV and upload just those again.\nA product code that appears twice in one file is imported once, from its last row.","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.16#0","canonicalFingerprint":"9i3lf8"},{"task":"Put each owner's area in brackets, like <code>Dana Okafor (checkout and payments)</code>. Tom isn't on call any more, so delete his line, and the page was last updated in December. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"text/plain","start":"# Who's who\n\nAsk the person who owns the area first. If they're away, ask in #shop.\n\nDana Okafor - checkout and payments\nKemal Aydin - search and the catalog\nPriya Raman - design and copy\nInes Moreau - deliveries and returns\nTom Berg - on call this week\n\nLast updated by Dana in November.","startCursor":{"line":2,"ch":0},"paths":[{"keys":["2","j","q","a","f","-","x","r","(","A",")","<Esc>","j","0","q","@","a","@","@","@","@","d","d","j","$","b","c","w","December","<Esc>"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay","linewise"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Who's who\n\nAsk the person who owns the area first. If they're away, ask in #shop.\n\nDana Okafor (checkout and payments)\nKemal Aydin (search and the catalog)\nPriya Raman (design and copy)\nInes Moreau (deliveries and returns)\n\nLast updated by Dana in December.","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.16#1","canonicalFingerprint":"apygjo"},{"task":"The tracker moved to Linear, so write the three ticket numbers as <code>NW-412</code> and so on, without the <code>#</code>. Search waits <code>200</code> ms now, not <code>300</code>. You can use any commands.","hint":"Make each change once in a way you can repeat. Then the dot, cgn or a macro does the rest.","mode":"text/plain","start":"Northwind shop, changes in 4.3\n\nFixed: the cart total ignored discounts on gift cards (#412)\nFixed: Dutch emails showed prices in pounds (#418)\nNew: saved addresses at checkout\nNew: a \"Buy it again\" button on past orders (#431)\nChanged: search waits 300 ms before it asks the server\n\nThanks to Dana, Kemal and Priya for testing.","startCursor":{"line":0,"ch":0},"paths":[{"keys":["/","#","<CR>","c","l","NW-","<Esc>","n",".","n",".","j","F","3","r","2"],"tier":"idiomatic","technique":"dot","core":["dot","search:n"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"Northwind shop, changes in 4.3\n\nFixed: the cart total ignored discounts on gift cards (NW-412)\nFixed: Dutch emails showed prices in pounds (NW-418)\nNew: saved addresses at checkout\nNew: a \"Buy it again\" button on past orders (NW-431)\nChanged: search waits 200 ms before it asks the server\n\nThanks to Dana, Kemal and Priya for testing.","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.16#2","canonicalFingerprint":"36d4kp"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> The dot, cgn, Visual selection and macros.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three or four changes in each of three real files, where most of them repeat.</p><p>You choose the commands here. When a change repeats, make it once in a way you can repeat, then use the dot, cgn or a macro for the rest. Watch for matches that should stay as they are. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"}}}