{"schemaVersion":1,"contentVersion":"3.4.0","id":"foundation.7","languages":{"javascript":{"id":"foundation.7","title":"Compose an edit","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p><strong>Before this lesson:</strong> Choose where typing begins.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><div class=\"pkeys\"><kbd>d</kbd> <kbd>c</kbd> <kbd>y</kbd> <kbd>dd</kbd> <kbd>cc</kbd> <kbd>yy</kbd> <kbd>p</kbd></div><h3>Example</h3><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><h4>Worked text</h4><pre class=\"lesson-example\">const message = \"pack bags\";</pre><h4>After the edit</h4><pre class=\"lesson-example\">const message = \"carry bags\";</pre><p>Use Start over to try again.</p>","teaches":["operator-motion","linewise","put"],"introduces":["d","c","y","p","dd","cc","yy","linewise"],"constraints":[],"drills":[{"task":"Delete the <code>console.log</code> that prints the token.","hint":"dd deletes the whole line, wherever the cursor is on it.","mode":"jsx","start":"import { request } from \"./base.js\";\n\nexport async function signIn(email, password) {\n  const { token } = await request(\"/sessions\", { method: \"POST\", body: { email, password } });\n  console.log(\"token\", token);\n  localStorage.setItem(\"northwind.token\", token);\n  return token;\n}","startCursor":{"line":3,"ch":10},"paths":[{"keys":["j","d","d"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"dd deletes the line, wherever the cursor is on it."}],"target":"import { request } from \"./base.js\";\n\nexport async function signIn(email, password) {\n  const { token } = await request(\"/sessions\", { method: \"POST\", body: { email, password } });\n  localStorage.setItem(\"northwind.token\", token);\n  return token;\n}","language":"javascript","evidence":"guided","canonicalKey":"foundation.7#0","canonicalFingerprint":"1p80kk"},{"task":"The recommendations endpoint isn't live yet, and <code>undefined</code> breaks the product page. Replace the TODO with <code>return [];</code> for now.","hint":"cc empties the line, keeps its indentation and puts you in Insert mode.","mode":"jsx","start":"import { request } from \"./shopApi.js\";\n\n// Products to show under \"You might also like\" on a product page.\nexport async function recommended(productId) {\n  // TODO: GET /products/:id/recommended once the endpoint is live\n}\n\nexport async function recentlyViewed(customerId) {\n  return request(`/customers/${customerId}/viewed`);\n}","startCursor":{"line":3,"ch":19},"paths":[{"keys":["j","c","c","return [];","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"cc keeps the indentation and replaces the rest of the line."}],"target":"import { request } from \"./shopApi.js\";\n\n// Products to show under \"You might also like\" on a product page.\nexport async function recommended(productId) {\n  return [];\n}\n\nexport async function recentlyViewed(customerId) {\n  return request(`/customers/${customerId}/viewed`);\n}","language":"javascript","evidence":"guided","canonicalKey":"foundation.7#1","canonicalFingerprint":"1ylg2zu"},{"task":"Add a pool for the read replica below the primary one. It's the same, with <code>replica</code> in place of <code>primary</code>.","hint":"yy copies the line and p puts the copy below. Then cw changes a word of the copy.","mode":"jsx","start":"import { createPool } from \"./driver.js\";\n\n// One pool per database server. Reads can go to any of them.\nexport const pools = [\n  createPool({ host: \"primary.db.internal\", port: 5432, max: 20 }),\n];","startCursor":{"line":2,"ch":3},"paths":[{"keys":["2","j","y","y","p","5","w","c","w","replica","<Esc>"],"tier":"idiomatic","technique":"put","core":["put","linewise","operator-motion"],"note":"yy and p copy the line below it, and cw changes the word that differs."}],"target":"import { createPool } from \"./driver.js\";\n\n// One pool per database server. Reads can go to any of them.\nexport const pools = [\n  createPool({ host: \"primary.db.internal\", port: 5432, max: 20 }),\n  createPool({ host: \"replica.db.internal\", port: 5432, max: 20 }),\n];","language":"javascript","evidence":"guided","canonicalKey":"foundation.7#2","canonicalFingerprint":"l3nhig"},{"task":"<code>formatDate</code> doesn't wait for anything, so callers get a promise for no reason. Remove <code>async </code>.","hint":"dw deletes the word and the space after it.","mode":"jsx","start":"// Dates on receipts and in emails, in the shop's time zone.\nconst formatter = new Intl.DateTimeFormat(\"nl-NL\", { dateStyle: \"long\", timeZone: \"Europe/Amsterdam\" });\n\nexport async function formatDate(date) {\n  return formatter.format(date);\n}","startCursor":{"line":4,"ch":2},"paths":[{"keys":["k","w","d","w"],"tier":"idiomatic","technique":"motion:w","core":["motion:w","operator-motion"],"note":"dw takes the space after the word with it, so the sentence still reads right."}],"target":"// Dates on receipts and in emails, in the shop's time zone.\nconst formatter = new Intl.DateTimeFormat(\"nl-NL\", { dateStyle: \"long\", timeZone: \"Europe/Amsterdam\" });\n\nexport function formatDate(date) {\n  return formatter.format(date);\n}","language":"javascript","evidence":"guided","canonicalKey":"foundation.7#3","canonicalFingerprint":"1gmbwg3"},{"task":"This file is for production. Point <code>bucket</code> at <code>northwind-assets</code>, without <code>-preproduction</code>.","hint":"Get to the dash before the word with w. From there, de deletes to the end of the word and keeps what comes after it.","mode":"jsx","start":"// Where product photos are uploaded.\nexport const storage = {\n  bucket: \"northwind-assets-preproduction\",\n  region: \"eu-west-1\",\n  cdn: \"https://images.northwind.shop\",\n  maxUploadMb: 10,\n};","startCursor":{"line":2,"ch":11},"paths":[{"keys":["3","w","d","e"],"tier":"idiomatic","technique":"motion:e","core":["motion:e","operator-motion"],"note":"de stops at the end of the word, so the closing quote stays. dw from the dash would only delete the dash."}],"target":"// Where product photos are uploaded.\nexport const storage = {\n  bucket: \"northwind-assets\",\n  region: \"eu-west-1\",\n  cdn: \"https://images.northwind.shop\",\n  maxUploadMb: 10,\n};","language":"javascript","evidence":"guided","canonicalKey":"foundation.7#4","canonicalFingerprint":"jeiqq4"}]},"python":{"id":"foundation.7","title":"Compose an edit","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p><strong>Before this lesson:</strong> Choose where typing begins.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><div class=\"pkeys\"><kbd>d</kbd> <kbd>c</kbd> <kbd>y</kbd> <kbd>dd</kbd> <kbd>cc</kbd> <kbd>yy</kbd> <kbd>p</kbd></div><h3>Example</h3><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><h4>Worked text</h4><pre class=\"lesson-example\">message = \"pack bags\"</pre><h4>After the edit</h4><pre class=\"lesson-example\">message = \"carry bags\"</pre><p>Use Start over to try again.</p>","teaches":["operator-motion","linewise","put"],"introduces":["d","c","y","p","dd","cc","yy","linewise"],"constraints":[],"drills":[{"task":"Delete the <code>print</code> that shows the token.","hint":"dd deletes the whole line, wherever the cursor is on it.","mode":"python","start":"from shop.accounts.http import client\n\n\ndef sign_in(session, email, password):\n    token = client.post(\"/sessions\", json={\"email\": email, \"password\": password})[\"token\"]\n    print(\"token\", token)\n    session[\"token\"] = token\n    return token","startCursor":{"line":4,"ch":10},"paths":[{"keys":["j","d","d"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"dd deletes the line, wherever the cursor is on it."}],"target":"from shop.accounts.http import client\n\n\ndef sign_in(session, email, password):\n    token = client.post(\"/sessions\", json={\"email\": email, \"password\": password})[\"token\"]\n    session[\"token\"] = token\n    return token","language":"python","evidence":"guided","canonicalKey":"foundation.7#0","canonicalFingerprint":"1p80kk"},{"task":"The recommendations endpoint isn't live yet, and <code>None</code> breaks the product page. Replace the TODO with <code>return []</code> for now.","hint":"cc empties the line, keeps its indentation and puts you in Insert mode.","mode":"python","start":"from shop.catalog.api import client\n\n\ndef recommended(product_id):\n    \"\"\"Products to show under \"You might also like\" on a product page.\"\"\"\n    pass  # TODO: GET /products/<id>/recommended once the endpoint is live\n\n\ndef recently_viewed(customer_id):\n    return client.get(f\"/customers/{customer_id}/viewed\")","startCursor":{"line":4,"ch":13},"paths":[{"keys":["j","c","c","return []","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"cc keeps the indentation and replaces the rest of the line."}],"target":"from shop.catalog.api import client\n\n\ndef recommended(product_id):\n    \"\"\"Products to show under \"You might also like\" on a product page.\"\"\"\n    return []\n\n\ndef recently_viewed(customer_id):\n    return client.get(f\"/customers/{customer_id}/viewed\")","language":"python","evidence":"guided","canonicalKey":"foundation.7#1","canonicalFingerprint":"1ylg2zu"},{"task":"Add a pool for the read replica below the primary one. It's the same, with <code>replica</code> in place of <code>primary</code>.","hint":"yy copies the line and p puts the copy below. Then cw changes a word of the copy.","mode":"python","start":"\"\"\"One pool per database server. Reads can go to any of them.\"\"\"\nfrom shop.db.driver import create_pool\n\nPOOLS = [\n    create_pool(host=\"primary.db.internal\", port=5432, max_size=20),\n]","startCursor":{"line":3,"ch":0},"paths":[{"keys":["j","y","y","p","4","w","c","w","replica","<Esc>"],"tier":"idiomatic","technique":"put","core":["put","linewise","operator-motion"],"note":"yy and p copy the line below it, and cw changes the word that differs."}],"target":"\"\"\"One pool per database server. Reads can go to any of them.\"\"\"\nfrom shop.db.driver import create_pool\n\nPOOLS = [\n    create_pool(host=\"primary.db.internal\", port=5432, max_size=20),\n    create_pool(host=\"replica.db.internal\", port=5432, max_size=20),\n]","language":"python","evidence":"guided","canonicalKey":"foundation.7#2","canonicalFingerprint":"l3nhig"},{"task":"<code>format_date</code> doesn't wait for anything, so callers get a coroutine for no reason. Remove <code>async </code>.","hint":"dw deletes the word and the space after it.","mode":"python","start":"\"\"\"Dates on receipts and in emails, in the shop's time zone.\"\"\"\nfrom zoneinfo import ZoneInfo\n\nSHOP_TZ = ZoneInfo(\"Europe/Amsterdam\")\n\n\nasync def format_date(moment):\n    return moment.astimezone(SHOP_TZ).strftime(\"%d %B %Y\")","startCursor":{"line":7,"ch":4},"paths":[{"keys":["k","0","d","w"],"tier":"idiomatic","technique":"motion:w","core":["motion:w","operator-motion"],"note":"dw takes the space after the word with it, so the sentence still reads right."}],"target":"\"\"\"Dates on receipts and in emails, in the shop's time zone.\"\"\"\nfrom zoneinfo import ZoneInfo\n\nSHOP_TZ = ZoneInfo(\"Europe/Amsterdam\")\n\n\ndef format_date(moment):\n    return moment.astimezone(SHOP_TZ).strftime(\"%d %B %Y\")","language":"python","evidence":"guided","canonicalKey":"foundation.7#3","canonicalFingerprint":"1gmbwg3"},{"task":"This file is for production. Point <code>STORAGE_BUCKET</code> at <code>northwind-assets</code>, without <code>-preproduction</code>.","hint":"Get to the dash before the word with w. From there, de deletes to the end of the word and keeps what comes after it.","mode":"python","start":"\"\"\"Where product photos are uploaded.\"\"\"\n\nSTORAGE_BUCKET = \"northwind-assets-preproduction\"\nSTORAGE_REGION = \"eu-west-1\"\nSTORAGE_CDN = \"https://images.northwind.shop\"\nMAX_UPLOAD_MB = 10","startCursor":{"line":2,"ch":18},"paths":[{"keys":["3","w","d","e"],"tier":"idiomatic","technique":"motion:e","core":["motion:e","operator-motion"],"note":"de stops at the end of the word, so the closing quote stays. dw from the dash would only delete the dash."}],"target":"\"\"\"Where product photos are uploaded.\"\"\"\n\nSTORAGE_BUCKET = \"northwind-assets\"\nSTORAGE_REGION = \"eu-west-1\"\nSTORAGE_CDN = \"https://images.northwind.shop\"\nMAX_UPLOAD_MB = 10","language":"python","evidence":"guided","canonicalKey":"foundation.7#4","canonicalFingerprint":"jeiqq4"}]},"text":{"id":"foundation.7","title":"Compose an edit","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p><strong>Before this lesson:</strong> Choose where typing begins.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><div class=\"pkeys\"><kbd>d</kbd> <kbd>c</kbd> <kbd>y</kbd> <kbd>dd</kbd> <kbd>cc</kbd> <kbd>yy</kbd> <kbd>p</kbd></div><h3>Example</h3><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><h4>Worked text</h4><pre class=\"lesson-example\">Message: pack bags</pre><h4>After the edit</h4><pre class=\"lesson-example\">Message: carry bags</pre><p>Use Start over to try again.</p>","teaches":["operator-motion","linewise","put"],"introduces":["d","c","y","p","dd","cc","yy","linewise"],"constraints":[],"drills":[{"task":"Tom has left. Delete his line.","hint":"dd deletes the whole line, wherever the cursor is on it.","mode":"text/plain","start":"# Who to ask\n\n- Dana: checkout and payments\n- Tom: the warehouse system\n- Kemal: the admin and reports\n- Priya: the website and emails","startCursor":{"line":2,"ch":7},"paths":[{"keys":["j","d","d"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"dd deletes the line, wherever the cursor is on it."}],"target":"# Who to ask\n\n- Dana: checkout and payments\n- Kemal: the admin and reports\n- Priya: the website and emails","language":"text","evidence":"guided","canonicalKey":"foundation.7#0","canonicalFingerprint":"1p80kk"},{"task":"We ship faster now. Replace the delivery time line with <code>Most orders arrive the next working day.</code>","hint":"cc empties the line, keeps its indentation and puts you in Insert mode.","mode":"text/plain","start":"Subject: When will my order arrive?\n\nHi Dana,\n\nThanks for your question about order 1042.\nDelivery takes three to five working days in the Netherlands.\nYou get an email with the tracking link when it leaves our warehouse.\n\nInes, Northwind customer care","startCursor":{"line":4,"ch":9},"paths":[{"keys":["j","c","c","Most orders arrive the next working day.","<Esc>"],"tier":"idiomatic","technique":"linewise","core":["linewise"],"note":"cc keeps the indentation and replaces the rest of the line."}],"target":"Subject: When will my order arrive?\n\nHi Dana,\n\nThanks for your question about order 1042.\nMost orders arrive the next working day.\nYou get an email with the tracking link when it leaves our warehouse.\n\nInes, Northwind customer care","language":"text","evidence":"guided","canonicalKey":"foundation.7#1","canonicalFingerprint":"1ylg2zu"},{"task":"Back up the replica too. Add a copy of the backup line below it, with <code>replica</code> in place of <code>primary</code>.","hint":"yy copies the line and p puts the copy below. Then cw changes a word of the copy.","mode":"text/plain","start":"# m h dom mon dow  command\nMAILTO=ops@northwind.shop\n0 2 * * * /opt/northwind/backup.sh --target primary\n30 3 * * 0 /opt/northwind/clean-old-backups.sh --days 30\n*/15 * * * * /opt/northwind/sync-stock.sh\n0 6 * * 1 /opt/northwind/weekly-report.sh","startCursor":{"line":1,"ch":0},"paths":[{"keys":["j","y","y","p","$","b","c","w","replica","<Esc>"],"tier":"idiomatic","technique":"put","core":["put","linewise","operator-motion"],"note":"yy and p copy the line below it, and cw changes the word that differs."}],"target":"# m h dom mon dow  command\nMAILTO=ops@northwind.shop\n0 2 * * * /opt/northwind/backup.sh --target primary\n0 2 * * * /opt/northwind/backup.sh --target replica\n30 3 * * 0 /opt/northwind/clean-old-backups.sh --days 30\n*/15 * * * * /opt/northwind/sync-stock.sh\n0 6 * * 1 /opt/northwind/weekly-report.sh","language":"text","evidence":"guided","canonicalKey":"foundation.7#2","canonicalFingerprint":"l3nhig"},{"task":"Don't oversell it. Remove <code>much </code> from the search item.","hint":"dw deletes the word and the space after it.","mode":"text/plain","start":"# Release 4.3\n\n- Search is now much faster on the orders page.\n- Order emails show the delivery window.\n- You can pay with a gift card at checkout.\n- The admin remembers your last filter.","startCursor":{"line":2,"ch":2},"paths":[{"keys":["3","w","d","w"],"tier":"idiomatic","technique":"motion:w","core":["motion:w","operator-motion"],"note":"dw takes the space after the word with it, so the sentence still reads right."}],"target":"# Release 4.3\n\n- Search is now faster on the orders page.\n- Order emails show the delivery window.\n- You can pay with a gift card at checkout.\n- The admin remembers your last filter.","language":"text","evidence":"guided","canonicalKey":"foundation.7#3","canonicalFingerprint":"1gmbwg3"},{"task":"These docs are for production. Make the bucket <code>northwind-assets</code>, without <code>-preproduction</code>.","hint":"Get to the dash before the word with w. From there, de deletes to the end of the word and keeps what comes after it.","mode":"text/plain","start":"# Product photos\n\nUpload photos from the admin, at least 1200 pixels wide.\nThey're stored in the northwind-assets-preproduction bucket and served from our CDN.\nThumbnails are made when you save the product.\nAsk Kemal if a photo doesn't show up after an hour.","startCursor":{"line":3,"ch":22},"paths":[{"keys":["3","w","d","e"],"tier":"idiomatic","technique":"motion:e","core":["motion:e","operator-motion"],"note":"de stops at the end of the word, so the closing quote stays. dw from the dash would only delete the dash."}],"target":"# Product photos\n\nUpload photos from the admin, at least 1200 pixels wide.\nThey're stored in the northwind-assets bucket and served from our CDN.\nThumbnails are made when you save the product.\nAsk Kemal if a photo doesn't show up after an hour.","language":"text","evidence":"guided","canonicalKey":"foundation.7#4","canonicalFingerprint":"jeiqq4"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose where typing begins.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><h2 class=\"prose-subhead\">Example</h2><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose where typing begins.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><h2 class=\"prose-subhead\">Example</h2><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose where typing begins.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Put an operator together with a motion to delete, change or copy text.</p><p>The operator says what to do and the motion says how far. d deletes and keeps you in Normal mode, c deletes and puts you in Insert mode, and y copies without deleting. de deletes to the end of a word. cw at the start of a word changes that word. Doubled, as dd, cc and yy, they work on the whole line. p puts copied text after the cursor, or below the current line if you copied a whole line.</p><h2 class=\"prose-subhead\">Example</h2><p>From p in “pack bags”, cw then “carry” then Esc gives “carry bags”. dw would delete the word and the space after it. yy then p puts a copy of the whole line below and keeps the original.</p><p>Use Start over to try again.</p></div></details>"}}}