"_dd throws a line in the bin without touching any jar; "+y and "+p reach the system clipboard in your editor.
Scene
Friday, 4:15 p.m. Tidying salsas.ts: three dead lines of old exports, and you want the first line of the file copied where they were. You yy it, dd the dead lines, press p, and get a dead line back. Again.
And the kitchen wants the finished recipe on their tablet, which isn't Vim at all.
From memory
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Copy this word into jar w.
press the keys…5 keys
1 of 2
Copy this word into jar w.
"wyiw
The bin
At the end of the shelf there's a bin, labelled _. Whatever goes in is gone, and no jar notices: "_dd deletes the line without touching the everyday jar, so the yank you made before is still there for p. (Vim calls it the black hole register.)
Afteryyj"_dd
""export const SALSAS = [VERDE, ROJA, DIABLO];↵
"_gone for good
After yy and then "_dd: the everyday jar still holds the yank, and the bin, as always, holds nothing.
Try it
Bin the dead lines✓ done
yy the first line, then bin the three // old: lines with "_dd, and put the yank where they were with P.
Fix the marked spots · 4 left
0000000000
1exportconstSALSAS=[VERDE,ROJA,DIABLO];
1// old: export const SALSAS = [VERDE, ROJA];
2// old: export const SPICY = [DIABLO];
3// old: export const MILD = [VERDE];
4exportconstSPECIAL=DIABLO;
, DIABLO
NORMALLoading the editor…0.0s1:1
⌨
This exercise needs a keyboard. Read on, and play it at your computer.
Check yourself
What comes out?
0000000000
1keep
1junk
2end
NORMAL
Keys pressed: yyj"_ddp
You yykeep, go down, "_dd the junk line, and p. What does the file say?
Pick an answer (or press its number), then watch the engine prove it.
Not quite. The bin took junk and no jar noticed, so the everyday jar still holds keep, and p puts it below end.
The jar by the door
By the door stands a jar labelled + that people outside the kitchen can reach: the system clipboard, shared with your browser, chat and every other program. "+yy copies a line out of Vim; "+p pastes in what you copied elsewhere. On Linux there's a second one, *, the text you last selected with the mouse; elsewhere * is the same as +.
From memory
Bin and door, from memory
Press the keys.
Delete this line without changing any register.
scroll here, then press the keys4 keys
1 of 3
Delete this line without changing any register.
"_dd
Challenge
Clear-out
Three tidy-ups. In each, one line moves somewhere else and the dead lines around it go. Cut the line that moves first, and keep it in the everyday jar until it lands: the file is only done when it's in its new place.
Stuck? Show a hint
Move the cursor onto the
0000000000
1
1
2
3
4
5
6
7
NORMALLoading the editor…0.0s1:1
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.
This exercise needs a keyboard. Read on, and play it at your computer.
To the tablet
The kitchen wants the whole recipe on their tablet. Copying it line by line with "+yy wouldn't work: each copy refills the jar and replaces the last. Highlight the lines and copy once: V, down to the ];, "+y.
Try it
To the tablet
Highlight the recipe from the first line to the ]; and copy it once with "+y. In this page the tablet is the bottom of the file, below the marker: G and "+p show what the kitchen would get.
Move the cursor onto the
0000000000
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
NORMALLoading the editor…0.0s1:1
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.