Inside vs around
Text objects name a thing from anywhere inside it: i is the filling, a the whole burrito, foil and all. ci" keeps the quotes, da( takes the brackets.
Tuesday, 9:10 a.m. The menu is moving out of menu.ts and into menu.json, so the website, the app and the kitchen display can all read one file. Names in quotes, tags in square brackets, every item in braces: everything you need to change today is wrapped in something.
Yesterday you asked the file where things were. Today you'll just name them.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
return.return.Name it, wherever you are
A motion says from here to there. A text object says this thing: this word, this string, these brackets. It goes after a verb, like any noun, and it works from anywhere inside the thing: with the cursor anywhere in "Garden Veggie", ci" changes the whole name. No walking to its start first.
The filling, or the whole burrito
Every text object comes in two sizes. i is inside: the filling, just the contents. a is around: the burrito and its foil. For a string the foil is the quotes, for brackets it's the brackets, and for a word it's the space beside it. So i" is the name, and a" is the name with its quotes.
What stays?
Predict it before the picture below shows it: the cursor is in Veggie, and you press da". What is left between "name": and "price"?
{ "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] }, { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] }, { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] }, { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },const fee = deliveryFee(zoneFor(stop), order);const fee = deliveryFee(zoneFor(stop), order);Fresh filling
The specials board, which changes every day: two names and one tag are different today. Same foil, new filling: ci" from anywhere inside each string.
This exercise needs a keyboard. Read on, and play it at your computer.
Foil and all
The old code called the menu like a function: data.menu.items(). In menu.json it's just data, so the brackets have to go. da( deletes the brackets and what's inside them, and like every text object it doesn't care where in the brackets you are. In Vim 9.1 and Neovim it doesn't even mind that you're a little before them on the line.
export const items = data.menu.items();export const items = data.menu.items;Throw out the foil
Three calls that should be plain values, then a doubled word in the log message. da( for the brackets, daw for the word.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Which foil?
The cursor is in Veggie, inside the quotes. You press daw. What does the name become?
Wrong size, put it back
Back on the specials board, two slips already made for you. Rice Bowl was meant to become Bean Bowl, and someone pressed daw instead of ciw; Churro Cup was meant to become Mini Churros, and ciw only took one word. Each time: look at what the object took, u, then make the edit the right size.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Inside or around, from memory
Press the keys. The cursor is somewhere inside the thing.
Wrapped values
Ten wrong strings, arguments and names across the codebase. Pick the object, inside or around, from wherever the cursor lands.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
The first menu.json
9:50. The kitchen's draft of menu.json, with five mistakes, top to bottom: a doubled word, a name the kitchen changed by mistake (it should say Garden Veggie), a misspelled tag, a currency in lowercase, and a closing hour off by one (it's 23). Name each thing; don't walk to it.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Extra practice optional
The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.
Wrapped, endlessly
Endless wrong strings, arguments and words. Change inside, delete around.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.