Learn Practice Daily golf Reference
Plugins & your editor·Lesson 1 of 4·8 min·0/8 exercisesPro

Surround

A wrapping station for track 6's foil: ys wraps a noun (ysiw"), cs swaps the wrapping (cs'"), ds takes it off; opening brackets wrap loosely, closing ones tightly.

Scene

Monday after launch, 9:30 a.m. Taco Turbo's new menu page is yours, word for word. Your answer is a better one by lunch, and the edits are all wrappings: single quotes that should be double, names that need an <em>, brackets nobody needs.

Wrappings are track 6's foil. A plugin turns them into verbs.

From memory

Warm-up from earlier chapters

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

Search for the word under the cursor.
press the keys…
1 of 2
Search for the word under the cursor.

A wrapping station

surround (vim-surround, by Tim Pope; built into several editors, see below) adds three verbs for the foil. ys wraps: ysiw" puts the word in quotes. cs swaps one foil for another: cs'" turns single quotes into double. ds takes the foil off and keeps the filling: ds( removes the brackets around you.

Before
x = 'hi'
cs'"
x = "hi"
Swap the foil: single quotes become double, the filling stays.
Before
name: Al
ysiw"
name: "Al"
ys, the noun iw, the foil ": the word, wrapped.
Try it

Swap the foil

Single quotes where the code uses double. cs'" from inside each string.

1 of 4Fix the marked spots · 2 left
1export const config = {
1 apiUrl: "https://api.byteburrito.dev",
2 currency: 'USD',
3 taxRate: 0.0875,
4 openHour: 11,
5 closeHour: 23,
6 slogan: "Code by day, burritos by night",
7};
NORMALLoading the editor…1/40.0s1:1

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

Loose or tight, and labels

With brackets, the opening one wraps loosely and the closing one tightly: ysiw( gives ( word ), ysiw) gives (word). yss wraps the whole line. A tag works as the foil too, as in the tags lesson: ysiwt then the tag, or ysiw<em>, gives <em>word</em>. In Visual mode, S and the foil wraps the highlight.

Check yourself

Loose or tight?

1call foo now
NORMAL
Keys pressed: ysiw(

You press ysiw( on foo. What does the line say?

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

Make up your mind

The design team wants new items marked. Brackets: ysiw) on new. Five minutes later, quotes instead: cs)". Ten minutes after that, nothing at all, the badge will do it: ds".

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.

Try it

Take the foil off

Brackets and quotes nobody needs. ds and the character, from inside each pair.

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.

Try it

The menu line

Two wrappings on one line: 'spicy' gets double quotes, and the two words Al Pastor get wrapped in <em>. The cursor is in spicy.

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.

Side by sideFinish the exercise above to see it.
From memory

The wrapping station, from memory

Press the keys.

Wrap this word in double quotes.
scroll here, then press the keys5 keys
1 of 4
Wrap this word in double quotes.
Challenge

The new menu page

Ten wrappings across the codebase: quotes to swap, wraps to add, wraps to take off.

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.