Learn Practice Daily golf Reference
Operators·Lesson 4 of 7·8 min·0/10 exercisesPro

Yank & put

y puts a copy in the jar, p and P pour it out after or before. Deletes fill the jar too, so xp and ddp swap letters and lines.

Scene

Tuesday, 1:15 p.m. The menu team drops by with tomorrow's special: barbacoa. It's almost exactly carnitas, an item you already have: same shape, a different name, a slightly higher price.

Copying a line is yy, you know that. Where does the copy go, and how do you get it back out?

From memory

Warm-up from earlier chapters

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

Join the next line onto this one.
press the keys…
1 of 2
Join the next line onto this one.

One jar

Picture a jar on the kitchen shelf. y puts a copy of what its noun covers into the jar, and nothing on screen changes. p pours the jar back out, after the cursor. So yy then p copies a line and puts the copy right below it: a duplicate in three keys.

Before
export const menu = [
{ id: "carnitas", name: "Carnitas", price: 10 },
];
yyp
export const menu = [
{ id: "carnitas", name: "Carnitas", price: 10 },
{ id: "carnitas", name: "Carnitas", price: 10 },
];
yy fills the jar with the whole line; p pours it out on a new line below.

p after, P before

P pours the same jar before the cursor instead. For a word you yanked with yw, that means right in front of the character you're on; p would put it right after.

Check yourself

Before or after?

1const total = sum;
NORMAL
Keys pressed: ywP

The cursor is on the t of total. You press yw, then P. What does the line say?

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

Words in the jar

Two signs for the counter came back with their words swapped. On the first word, dw takes it (and its space) into the jar, w steps past the next word, and P pours it back in front of the cursor.

1 of 2Change the red text to Extra Spicy
1export const SIGNS = [
1 "Spicy Extra Salsa",
2 "Hot Very Sauce",
3];
NORMALLoading the editor…1/20.0s1:1

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

Whole lines go on whole lines

The jar remembers what kind of thing it holds. Fill it with whole lines (yy, dd) and p doesn't split the line you're on: it pours them onto a new line below, and P onto a new line above, wherever the cursor is.

Try it

Clone the line

Each file is missing a copy of one line. Fill the jar with yy on the line to copy, then p.

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.

Deletes fill the jar too

Whatever you take out goes in the jar as well: x, dw and dd all fill it. So delete-then-put moves text. Two tiny recipes come out of that: xp swaps two letters (take one out, pour it back one later), and ddp swaps two lines.

Before
kitchen.open();
const kitchen = new Kitchen();
kitchen.printer.warmUp();
ddp
const kitchen = new Kitchen();
kitchen.open();
kitchen.printer.warmUp();
dd takes the line into the jar, p pours it back below the next one: two lines swapped.
Try it

Swap them back

Two letters in the wrong order (xp on the first of them), or two lines in the wrong order (ddp on the first of them).

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

What's in the jar?

1{ id: "carnitas", price: 10 },
1#{ id: "birria", price: 11 },
NORMAL
Keys pressed: yyjxp

You yy the carnitas line, press j, x the stray #, then p. What happens?

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

Refill the jar

That just happened in menu.ts. Take the wrong pour back with u, then do it in an order the jar survives: the stray # is already gone, so fill the jar with the carnitas line now and pour it below.

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

Fill and pour

From memory.

Copy this whole line into the jar.
scroll here, then press the keys2 keys
1 of 5
Copy this whole line into the jar.
Challenge

Copy shop

Missing copies, swapped letters and lines in the wrong order, across the codebase. Fill the jar, pour it where it goes.

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

Clone the specials

Barbacoa is carnitas with a new name and a price one higher. Make a copy of the carnitas line; in the copy, the id becomes barbacoa, the name Barbacoa and the price 11. Then barbacoa goes above carnitas, so the menu stays alphabetical.

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.

Tomorrow's specialFinish the exercise above to see it.

Extra practice optional

The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.

Endless

Copy shop, after hours

Endless copies to make and things to swap back.

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.