{"schemaVersion":1,"contentVersion":"3.4.0","id":"foundation.2","languages":{"javascript":{"id":"foundation.2","title":"Recover and cancel","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p><strong>Before this lesson:</strong> First edits and modes.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><div class=\"pkeys\"><kbd>u</kbd> <kbd>Ctrl-r</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><h4>Worked text</h4><pre class=\"lesson-example\">const message = \"note\";</pre><h4>Before undo</h4><pre class=\"lesson-example\">const message = \"wrong note\";</pre><p>Use Start over to try again.</p>","teaches":["undo"],"introduces":["u","<C-r>"],"constraints":[],"drills":[{"task":"You deleted the <code>attempts</code> line by mistake. Get it back.","hint":"u undoes your last change, wherever the cursor is.","mode":"jsx","start":"import { Queue } from \"bullmq\";\nimport { redis } from \"../lib/redis.js\";\n\n// Sends order emails in the background.\nexport const emailQueue = new Queue(\"emails\", {\n  connection: redis,\n  defaultJobOptions: {\n    backoff: { type: \"exponential\", delay: 2000 },\n    removeOnComplete: true,\n  },\n});","startCursor":{"line":4,"ch":0},"paths":[{"keys":["u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"u brings back what your last change took away, wherever the cursor is."}],"target":"import { Queue } from \"bullmq\";\nimport { redis } from \"../lib/redis.js\";\n\n// Sends order emails in the background.\nexport const emailQueue = new Queue(\"emails\", {\n  connection: redis,\n  defaultJobOptions: {\n    attempts: 5,\n    backoff: { type: \"exponential\", delay: 2000 },\n    removeOnComplete: true,\n  },\n});","language":"javascript","evidence":"guided","setup":{"from":"import { Queue } from \"bullmq\";\nimport { redis } from \"../lib/redis.js\";\n\n// Sends order emails in the background.\nexport const emailQueue = new Queue(\"emails\", {\n  connection: redis,\n  defaultJobOptions: {\n    attempts: 5,\n    backoff: { type: \"exponential\", delay: 2000 },\n    removeOnComplete: true,\n  },\n});","at":{"line":7,"ch":4},"keys":["d","d"]},"canonicalKey":"foundation.2#0","canonicalFingerprint":"18znnaq"},{"task":"You made <code>fetch</code> send the sign-in cookie, then undid that by mistake. Bring the change back.","hint":"Ctrl-r redoes the change you just undid.","mode":"jsx","start":"import { API_URL } from \"../config.js\";\n\n// Loads the signed-in customer, or null for a guest.\nexport async function loadSession() {\n  const response = await fetch(`${API_URL}/session`);\n  if (response.status === 401) return null;\n  if (!response.ok) throw new Error(`Session: HTTP ${response.status}`);\n  const { customer } = await response.json();\n  return customer;\n}","startCursor":{"line":6,"ch":2},"paths":[{"keys":["<C-r>"],"tier":"idiomatic","technique":"Redo a change","core":[],"note":"Ctrl-r makes the change you undid again, however many keys it took to type."}],"target":"import { API_URL } from \"../config.js\";\n\n// Loads the signed-in customer, or null for a guest.\nexport async function loadSession() {\n  const response = await fetch(`${API_URL}/session`, { credentials: \"include\" });\n  if (response.status === 401) return null;\n  if (!response.ok) throw new Error(`Session: HTTP ${response.status}`);\n  const { customer } = await response.json();\n  return customer;\n}","language":"javascript","evidence":"guided","setup":{"from":"import { API_URL } from \"../config.js\";\n\n// Loads the signed-in customer, or null for a guest.\nexport async function loadSession() {\n  const response = await fetch(`${API_URL}/session`);\n  if (response.status === 401) return null;\n  if (!response.ok) throw new Error(`Session: HTTP ${response.status}`);\n  const { customer } = await response.json();\n  return customer;\n}","at":{"line":4,"ch":25},"keys":["f",")","i",", { credentials: \"include\" }","<Esc>","u"]},"canonicalKey":"foundation.2#1","canonicalFingerprint":"l25c4x"},{"task":"By mistake, you typed a comment after <code>tracesSampleRate: 0.2,</code> and then deleted the <code>sendDefaultPii</code> line. Put the file back the way it was.","hint":"Each u undoes one change. Text you typed in one go, up to Esc, is one change, and so is a dd.","mode":"jsx","start":"import * as Sentry from \"@sentry/node\";\n\n// Error reports from the API. Only production sends them.\nSentry.init({\n  dsn: process.env.SENTRY_DSN,\n  environment: process.env.NODE_ENV,\n  tracesSampleRate: 0.2, // or 0.5?\n});","startCursor":{"line":3,"ch":0},"paths":[{"keys":["u","u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"Two changes take two u. 2u does the same in as many keys."}],"target":"import * as Sentry from \"@sentry/node\";\n\n// Error reports from the API. Only production sends them.\nSentry.init({\n  dsn: process.env.SENTRY_DSN,\n  environment: process.env.NODE_ENV,\n  tracesSampleRate: 0.2,\n  sendDefaultPii: false,\n});","language":"javascript","evidence":"guided","setup":{"from":"import * as Sentry from \"@sentry/node\";\n\n// Error reports from the API. Only production sends them.\nSentry.init({\n  dsn: process.env.SENTRY_DSN,\n  environment: process.env.NODE_ENV,\n  tracesSampleRate: 0.2,\n  sendDefaultPii: false,\n});","at":{"line":6,"ch":2},"keys":["A"," // or 0.5?","<Esc>","j","d","d"]},"canonicalKey":"foundation.2#2","canonicalFingerprint":"13r9xl6"}]},"python":{"id":"foundation.2","title":"Recover and cancel","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p><strong>Before this lesson:</strong> First edits and modes.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><div class=\"pkeys\"><kbd>u</kbd> <kbd>Ctrl-r</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><h4>Worked text</h4><pre class=\"lesson-example\">message = \"note\"</pre><h4>Before undo</h4><pre class=\"lesson-example\">message = \"wrong note\"</pre><p>Use Start over to try again.</p>","teaches":["undo"],"introduces":["u","<C-r>"],"constraints":[],"drills":[{"task":"You deleted the <code>TIMEOUT</code> line by mistake. Get it back.","hint":"u undoes your last change, wherever the cursor is.","mode":"python","start":"\"\"\"Cache settings. Redis in production, memory in tests.\"\"\"\nimport os\n\nCACHES = {\n    \"default\": {\n        \"BACKEND\": \"django.core.cache.backends.redis.RedisCache\",\n        \"LOCATION\": os.environ[\"REDIS_URL\"],\n        \"KEY_PREFIX\": \"shop\",\n    }\n}","startCursor":{"line":3,"ch":0},"paths":[{"keys":["u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"u brings back what your last change took away, wherever the cursor is."}],"target":"\"\"\"Cache settings. Redis in production, memory in tests.\"\"\"\nimport os\n\nCACHES = {\n    \"default\": {\n        \"BACKEND\": \"django.core.cache.backends.redis.RedisCache\",\n        \"LOCATION\": os.environ[\"REDIS_URL\"],\n        \"TIMEOUT\": 300,\n        \"KEY_PREFIX\": \"shop\",\n    }\n}","language":"python","evidence":"guided","setup":{"from":"\"\"\"Cache settings. Redis in production, memory in tests.\"\"\"\nimport os\n\nCACHES = {\n    \"default\": {\n        \"BACKEND\": \"django.core.cache.backends.redis.RedisCache\",\n        \"LOCATION\": os.environ[\"REDIS_URL\"],\n        \"TIMEOUT\": 300,\n        \"KEY_PREFIX\": \"shop\",\n    }\n}","at":{"line":7,"ch":8},"keys":["d","d"]},"canonicalKey":"foundation.2#0","canonicalFingerprint":"18znnaq"},{"task":"You deleted the <code>print</code> you left in for debugging, then undid that by mistake. Delete it again.","hint":"Ctrl-r redoes the change you just undid.","mode":"python","start":"from shop.mail import send_template\n\n\ndef send_order_confirmation(order):\n    \"\"\"Emails the customer a summary of their order.\"\"\"\n    print(\"sending confirmation\", order.number)\n    send_template(\n        \"order_confirmation\",\n        recipient=order.customer.email,\n        subject=f\"Your order {order.number}\",\n        context={\"order\": order},\n    )","startCursor":{"line":6,"ch":4},"paths":[{"keys":["<C-r>"],"tier":"idiomatic","technique":"Redo a change","core":[],"note":"Ctrl-r makes the change you undid again, however many keys it took to type."}],"target":"from shop.mail import send_template\n\n\ndef send_order_confirmation(order):\n    \"\"\"Emails the customer a summary of their order.\"\"\"\n    send_template(\n        \"order_confirmation\",\n        recipient=order.customer.email,\n        subject=f\"Your order {order.number}\",\n        context={\"order\": order},\n    )","language":"python","evidence":"guided","setup":{"from":"from shop.mail import send_template\n\n\ndef send_order_confirmation(order):\n    \"\"\"Emails the customer a summary of their order.\"\"\"\n    print(\"sending confirmation\", order.number)\n    send_template(\n        \"order_confirmation\",\n        recipient=order.customer.email,\n        subject=f\"Your order {order.number}\",\n        context={\"order\": order},\n    )","at":{"line":5,"ch":4},"keys":["d","d","u"]},"canonicalKey":"foundation.2#1","canonicalFingerprint":"l25c4x"},{"task":"By mistake, you added <code>TEST_MODE = True</code> below the import and then deleted the <code>CURRENCY</code> line. Put the file back the way it was.","hint":"Each u undoes one change. Text you typed in one go, up to Esc, is one change, and so is a dd.","mode":"python","start":"\"\"\"Payment settings. The keys come from the environment.\"\"\"\nimport os\nTEST_MODE = True\n\nPAYMENTS_PROVIDER = \"mollie\"\nMOLLIE_API_KEY = os.environ[\"MOLLIE_API_KEY\"]\nMOLLIE_PROFILE_ID = os.environ[\"MOLLIE_PROFILE_ID\"]\nPAYMENT_METHODS = [\"ideal\", \"creditcard\", \"bancontact\"]","startCursor":{"line":6,"ch":0},"paths":[{"keys":["u","u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"Two changes take two u. 2u does the same in as many keys."}],"target":"\"\"\"Payment settings. The keys come from the environment.\"\"\"\nimport os\n\nPAYMENTS_PROVIDER = \"mollie\"\nMOLLIE_API_KEY = os.environ[\"MOLLIE_API_KEY\"]\nMOLLIE_PROFILE_ID = os.environ[\"MOLLIE_PROFILE_ID\"]\nPAYMENT_METHODS = [\"ideal\", \"creditcard\", \"bancontact\"]\nCURRENCY = \"eur\"","language":"python","evidence":"guided","setup":{"from":"\"\"\"Payment settings. The keys come from the environment.\"\"\"\nimport os\n\nPAYMENTS_PROVIDER = \"mollie\"\nMOLLIE_API_KEY = os.environ[\"MOLLIE_API_KEY\"]\nMOLLIE_PROFILE_ID = os.environ[\"MOLLIE_PROFILE_ID\"]\nPAYMENT_METHODS = [\"ideal\", \"creditcard\", \"bancontact\"]\nCURRENCY = \"eur\"","at":{"line":1,"ch":0},"keys":["o","TEST_MODE = True","<Esc>","G","d","d"]},"canonicalKey":"foundation.2#2","canonicalFingerprint":"13r9xl6"}]},"text":{"id":"foundation.2","title":"Recover and cancel","moduleName":"Editing foundations","tips":"","concept":"<p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p><strong>Before this lesson:</strong> First edits and modes.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><div class=\"pkeys\"><kbd>u</kbd> <kbd>Ctrl-r</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><h4>Worked text</h4><pre class=\"lesson-example\">Message: note</pre><h4>Before undo</h4><pre class=\"lesson-example\">Message: wrong note</pre><p>Use Start over to try again.</p>","teaches":["undo"],"introduces":["u","<C-r>"],"constraints":[],"drills":[{"task":"You deleted Monday's line from the rota by mistake. Get it back.","hint":"u undoes your last change, wherever the cursor is.","mode":"text/plain","start":"# Support rota, week 46\n\nWho answers the support inbox each morning.\n\n- Tuesday: Priya\n- Wednesday: Tom\n- Thursday: Dana\n- Friday: Lena\n\nSwap days in #support, and tell Lena.","startCursor":{"line":7,"ch":0},"paths":[{"keys":["u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"u brings back what your last change took away, wherever the cursor is."}],"target":"# Support rota, week 46\n\nWho answers the support inbox each morning.\n\n- Monday: Dana\n- Tuesday: Priya\n- Wednesday: Tom\n- Thursday: Dana\n- Friday: Lena\n\nSwap days in #support, and tell Lena.","language":"text","evidence":"guided","setup":{"from":"# Support rota, week 46\n\nWho answers the support inbox each morning.\n\n- Monday: Dana\n- Tuesday: Priya\n- Wednesday: Tom\n- Thursday: Dana\n- Friday: Lena\n\nSwap days in #support, and tell Lena.","at":{"line":4,"ch":0},"keys":["d","d"]},"canonicalKey":"foundation.2#0","canonicalFingerprint":"18znnaq"},{"task":"You added a line about urgent calls below the invoices line, then undid it by mistake. Bring it back.","hint":"Ctrl-r redoes the change you just undid.","mode":"text/plain","start":"Subject: Out of office until 18 November\n\nHi,\n\nI'm away until Monday 18 November, with no access to email.\nFor orders and returns, write to help@northwind.shop.\nFor invoices, write to accounts@northwind.shop.\n\nThanks,\nSam","startCursor":{"line":4,"ch":0},"paths":[{"keys":["<C-r>"],"tier":"idiomatic","technique":"Redo a change","core":[],"note":"Ctrl-r makes the change you undid again, however many keys it took to type."}],"target":"Subject: Out of office until 18 November\n\nHi,\n\nI'm away until Monday 18 November, with no access to email.\nFor orders and returns, write to help@northwind.shop.\nFor invoices, write to accounts@northwind.shop.\nAnything urgent? Call Priya on 020 7946 0321.\n\nThanks,\nSam","language":"text","evidence":"guided","setup":{"from":"Subject: Out of office until 18 November\n\nHi,\n\nI'm away until Monday 18 November, with no access to email.\nFor orders and returns, write to help@northwind.shop.\nFor invoices, write to accounts@northwind.shop.\n\nThanks,\nSam","at":{"line":6,"ch":0},"keys":["o","Anything urgent? Call Priya on 020 7946 0321.","<Esc>","u"]},"canonicalKey":"foundation.2#1","canonicalFingerprint":"l25c4x"},{"task":"By mistake, you typed <code> Tom?</code> after the release notes step and then deleted step 4. Put the file back the way it was.","hint":"Each u undoes one change. Text you typed in one go, up to Esc, is one change, and so is a dd.","mode":"text/plain","start":"# Release 4.2 checklist\n\n1. Freeze the main branch on Tuesday.\n2. Run the end-to-end tests on staging.\n3. Write the release notes. Tom?\n5. Watch the error dashboard for an hour.\n\nAsk in #releases if a step fails.","startCursor":{"line":2,"ch":0},"paths":[{"keys":["u","u"],"tier":"idiomatic","technique":"undo","core":["undo"],"note":"Two changes take two u. 2u does the same in as many keys."}],"target":"# Release 4.2 checklist\n\n1. Freeze the main branch on Tuesday.\n2. Run the end-to-end tests on staging.\n3. Write the release notes.\n4. Tag the release and deploy.\n5. Watch the error dashboard for an hour.\n\nAsk in #releases if a step fails.","language":"text","evidence":"guided","setup":{"from":"# Release 4.2 checklist\n\n1. Freeze the main branch on Tuesday.\n2. Run the end-to-end tests on staging.\n3. Write the release notes.\n4. Tag the release and deploy.\n5. Watch the error dashboard for an hour.\n\nAsk in #releases if a step fails.","at":{"line":4,"ch":0},"keys":["A"," Tom?","<Esc>","j","d","d"]},"canonicalKey":"foundation.2#2","canonicalFingerprint":"13r9xl6"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> First edits and modes.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><h2 class=\"prose-subhead\">Example</h2><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> First edits and modes.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><h2 class=\"prose-subhead\">Example</h2><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> First edits and modes.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Undo a change, redo it, and cancel a command you started without changing any text.</p><p>u undoes one change in Normal mode and Ctrl-r redoes it. Ctrl-r is not the same as the site's Start over shortcut. Everything you type between i and Esc is one change, however long it is, and so is a command like dd. u works wherever the cursor is, and takes it back to where the change was. Esc cancels an operator you started, such as d, and it also leaves Insert mode. Start over puts this exercise back the way it started, mistake and all. It doesn't touch your saved progress.</p><h2 class=\"prose-subhead\">Example</h2><p>If you type “wrong ” before “note”, Esc then u removes all of it, and Ctrl-r brings it back. If you press d and change your mind before the motion, press Esc. Then make the edit you meant.</p><p>Use Start over to try again.</p></div></details>"}}}