Learn Practice Daily golf Reference
Text objects·Lesson 1 of 8·9 min·0/9 exercisesPro

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.

Scene

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.

From memory

Warm-up from earlier chapters

Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.

Delete from here up to the next return.
press the keys…9 keys
1 of 2
Delete from here up to the next 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.

1 { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
NORMALLoading the editor…1:23

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.

Check yourself

What stays?

1 { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
NORMAL
Keys pressed: da"

Predict it before the picture below shows it: the cursor is in Veggie, and you press da". What is left between "name": and "price"?

Pick an answer (or press its number), then watch the engine prove it.
i"
{ "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
a"
{ "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
iw
{ "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
aw
{ "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
From the same cursor: the filling (i) and the whole burrito (a), for a string and for a word.
i(
const fee = deliveryFee(zoneFor(stop), order);
a(
const fee = deliveryFee(zoneFor(stop), order);
Brackets work the same way: i( is everything between them, a( takes the brackets too.
Try it

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.

1 of 3Change the red text to Rice
1{
1 "specials": [
2 { "name": "Burrito Bowl", "price": 8.5 },
3 { "name": "Churro Box", "price": 4, "tags": ["sweet"] },
4 { "name": "Horchata", "price": 3 }
5 ]
6}
NORMALLoading the editor…1/30.0s1:1

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.

Before
export const items = data.menu.items();
da(
export const items = data.menu.items;
da( from the word before the brackets: the brackets go, foil and all.
Try it

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.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Check yourself

Which foil?

1 { "name": "Garden Veggie", "price": 8.25, "tags": ["vegan"] },
NORMAL
Keys pressed: daw

The cursor is in Veggie, inside the quotes. You press daw. What does the name become?

Pick an answer (or press its number), then watch the engine prove it.
Try it

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
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

From memory

Inside or around, from memory

Press the keys. The cursor is somewhere inside the thing.

Change the text inside these quotes.
scroll here, then press the keys3 keys
1 of 5
Change the text inside these quotes.
Challenge

Wrapped values

Ten wrong strings, arguments and names across the codebase. Pick the object, inside or around, from wherever the cursor lands.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Boss round

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
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This 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.

Endless

Wrapped, endlessly

Endless wrong strings, arguments and words. Change inside, delete around.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.