{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.14","languages":{"javascript":{"id":"intermediate.14","title":"Record, stop and replay","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h3>Example</h3><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p>","teaches":["macro:again"],"introduces":["q","@","A","I","j","0"],"constraints":[],"drills":[{"task":"Prices and the page number arrive as strings. Wrap the values of <code>minPrice</code>, <code>maxPrice</code> and <code>page</code> in <code>Number(…)</code>.","hint":"Record the change on the first line with qa. Then go to each of the others and play it with @a, and @@ after that.","mode":"jsx","start":"// Query parameters arrive as strings. This turns them into the filters the API expects.\nexport function readFilters(params) {\n  return {\n    category: params.get(\"category\"),\n    minPrice: params.get(\"min\"),\n    brand: params.get(\"brand\"),\n    maxPrice: params.get(\"max\"),\n    sort: params.get(\"sort\") ?? \"newest\",\n    color: params.get(\"color\"),\n    page: params.get(\"page\"),\n    inStock: params.has(\"in-stock\"),\n  };\n}","startCursor":{"line":3,"ch":4},"paths":[{"keys":["j","q","a","^","W","i","Number(","<Esc>","$","i",")","<Esc>","q","2","j","@","a","3","j","@","@"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay"],"note":"A macro repeats a change made of several commands, which the dot can't. Recording already changed the first line."}],"target":"// Query parameters arrive as strings. This turns them into the filters the API expects.\nexport function readFilters(params) {\n  return {\n    category: params.get(\"category\"),\n    minPrice: Number(params.get(\"min\")),\n    brand: params.get(\"brand\"),\n    maxPrice: Number(params.get(\"max\")),\n    sort: params.get(\"sort\") ?? \"newest\",\n    color: params.get(\"color\"),\n    page: Number(params.get(\"page\")),\n    inStock: params.has(\"in-stock\"),\n  };\n}","language":"javascript","evidence":"guided","canonicalKey":"intermediate.14#0","canonicalFingerprint":"b3t8pz"}]},"python":{"id":"intermediate.14","title":"Record, stop and replay","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h3>Example</h3><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p>","teaches":["macro:again"],"introduces":["q","@","A","I","j","0"],"constraints":[],"drills":[{"task":"Prices and the page number arrive as strings. Wrap the values of <code>min_price</code>, <code>max_price</code> and <code>page</code> in <code>int(…)</code>.","hint":"Record the change on the first line with qa. Then go to each of the others and play it with @a, and @@ after that.","mode":"python","start":"def read_filters(params):\n    \"\"\"Query parameters arrive as strings. This turns them into the API's filters.\"\"\"\n    return {\n        \"category\": params.get(\"category\"),\n        \"min_price\": params.get(\"min\"),\n        \"brand\": params.get(\"brand\"),\n        \"max_price\": params.get(\"max\"),\n        \"sort\": params.get(\"sort\", \"newest\"),\n        \"color\": params.get(\"color\"),\n        \"page\": params.get(\"page\", \"1\"),\n        \"in_stock\": \"in-stock\" in params,\n    }","startCursor":{"line":3,"ch":8},"paths":[{"keys":["j","q","a","^","W","i","int(","<Esc>","$","i",")","<Esc>","q","2","j","@","a","3","j","@","@"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay"],"note":"A macro repeats a change made of several commands, which the dot can't. Recording already changed the first line."}],"target":"def read_filters(params):\n    \"\"\"Query parameters arrive as strings. This turns them into the API's filters.\"\"\"\n    return {\n        \"category\": params.get(\"category\"),\n        \"min_price\": int(params.get(\"min\")),\n        \"brand\": params.get(\"brand\"),\n        \"max_price\": int(params.get(\"max\")),\n        \"sort\": params.get(\"sort\", \"newest\"),\n        \"color\": params.get(\"color\"),\n        \"page\": int(params.get(\"page\", \"1\")),\n        \"in_stock\": \"in-stock\" in params,\n    }","language":"python","evidence":"guided","canonicalKey":"intermediate.14#0","canonicalFingerprint":"b3t8pz"}]},"text":{"id":"intermediate.14","title":"Record, stop and replay","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h3>Example</h3><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p>","teaches":["macro:again"],"introduces":["q","@","A","I","j","0"],"constraints":[],"drills":[{"task":"Mail clients want the addresses in angle brackets. Put <code>&lt;</code> and <code>&gt;</code> around the three that don't have them yet.","hint":"Record the change on the first line with qa. Then go to each of the others and play it with @a, and @@ after that.","mode":"text/plain","start":"Who to email when something breaks, by area:\n\nPayments: Dana Okafor <dana@northwind.shop>\nSearch: Kemal Aydin kemal@northwind.shop\nDeliveries: Ines Moreau <ines@northwind.shop>\nDesign: Priya Raman priya@northwind.shop\nReturns: Tom Berg <tom@northwind.shop>\nHosting: Ana Silva <ana@northwind.shop>\nAccounts: Ben Hall ben@northwind.shop","startCursor":{"line":2,"ch":0},"paths":[{"keys":["j","q","a","$","B","i","<","<Esc>","A",">","<Esc>","q","2","j","@","a","3","j","@","@"],"tier":"idiomatic","technique":"macro:again","core":["macro:again","macro:replay"],"note":"A macro repeats a change made of several commands, which the dot can't. Recording already changed the first line."}],"target":"Who to email when something breaks, by area:\n\nPayments: Dana Okafor <dana@northwind.shop>\nSearch: Kemal Aydin <kemal@northwind.shop>\nDeliveries: Ines Moreau <ines@northwind.shop>\nDesign: Priya Raman <priya@northwind.shop>\nReturns: Tom Berg <tom@northwind.shop>\nHosting: Ana Silva <ana@northwind.shop>\nAccounts: Ben Hall <ben@northwind.shop>","language":"text","evidence":"guided","canonicalKey":"intermediate.14#0","canonicalFingerprint":"b3t8pz"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h2 class=\"prose-subhead\">Example</h2><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h2 class=\"prose-subhead\">Example</h2><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Insertion, positioning and repetition.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Record a macro, remember that recording already made one edit, then replay it.</p><p>qa starts recording into register a, and q in Normal mode stops it. @a replays the macro and @@ replays the last one you used. Recording makes the first edit for real. A macro pays off when each line needs more than one change, which the dot can't repeat. Start it with a move such as ^ or 0, so it works wherever the cursor is on the line.</p><h2 class=\"prose-subhead\">Example</h2><p>To wrap a value in Number( and close it before the comma, record ^W, iNumber( and Esc, then $i) and Esc, then q. Go to the next line that needs it and press @a, and @@ for the one after.</p><p>Use Start over to try again.</p></div></details>"}}}