Learn Practice Daily golf Reference
Ex & substitution·Lesson 6 of 7·7 min·0/6 exercisesPro

Copy, move, sort

Orders that rearrange the lines: :t copies them to below a line you name (and leaves the jars alone), :m moves them, and :sort lines them up (u drops duplicates, n by number, a range keeps the heading out).

Scene

Thursday, 5:30 p.m. Last chores before migration night. The courier list in the docs needs its header repeated at the bottom, as every internal page does; a module has its export default at the top where the linter wants it at the bottom; and the list of courier zones has duplicates and isn't sorted.

Moving lines around is one more kind of order on the slip.

From memory

Warm-up from earlier chapters

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

Add , to the end of every line that isn't empty.
press the keys…15 keys
1 of 2
Add , to the end of every line that isn't empty.

Copy these to there

:t copies the slip's lines to below the line you name after it (read it as copy to). :t. copies the line you're on to just below itself; :1,2t$ copies lines 1 and 2 to the end of the file; :t0 copies to the very top. Nothing goes in any jar, so your registers stay as they were.

Before
// Internal, do not share.
courier 7: Wynwood
courier 12: Brickell
:1t$↵
// Internal, do not share.
courier 7: Wynwood
courier 12: Brickell
// Internal, do not share.
Line 1, copied to after the last line ($).
Try it

The header, again

Three steps. Downtown's line got pasted into the header: cut it with dd, so it's in the jar. Copy the two header lines to the end of the page with one slip, :1,2t$↵. Then put Downtown back under Edgewater with p: the jar still holds it, because :t never touched it. (Copy the header with yy and p instead, and the jar would hold the header.)

1 of 3Delete the line marked red
1// Byte Burrito couriers. Internal, do not share.
1// Last checked: Thursday.
2courier 44: Downtown
3
4courier 7: Wynwood
5courier 12: Brickell
6courier 31: Edgewater
NORMALLoading the editor…1/30.0s1:1

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

Move these to there

:m moves instead of copying: :m$ sends the line you're on to the bottom, :m0 to the top, :m+1 down past the next line. With a range in front, a whole block moves at once: :'<,'>m0.

Try it

Export at the bottom

The export default line goes to the bottom of the file. The cursor is on it: :m$↵.

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.

Line them up

:sort sorts the lines of the range, the whole file if you give none. :sort u also drops lines that appear twice, and :sort n sorts by the first number on each line, so that 9 comes before 10.

Before
wynwood
brickell
edgewater
brickell
:sort u↵
brickell
edgewater
wynwood
In order, and brickell only once.
Check yourself

Ten before nine?

110
19
2100
NORMAL
Keys pressed: :sort↵

You send :sort↵ on 10, 9 and 100. In what order are they?

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

Lists in order

Three lists, three decisions: a plain sort, one with duplicates, and courier ids by number under a heading that has to stay on top. The line under the editor says which is which. (Curious? Sort the last one without a range, look where the heading went, and u.)

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

Rearranging, from memory

Press the keys.

Copy this line to just below itself.
scroll here, then press the keys4 keys
1 of 4
Copy this line to just below itself.