Repeat substitutions
The kitchen keeps the last slip: :&&↵ sends it again on this line with its flags, g& to every line (with your last search as the pattern, so :%&&↵ after a search); and * then :%s//new/g renames the word you pointed at.
Thursday, 1:30 p.m. You write a careful slip for one line, :s/\<rider\>/courier/g, whole words only, so riders and riderCount wait for their own decisions. It works. Now the same order is wanted on a few lines further down, and then on every line of the file.
Writing the slip out again is how typos get in. The kitchen keeps a copy of the last one.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
user on this line in brackets, using the match itself.user on this line in brackets, using the match itself.The same slip again
:&&↵ sends the last slip again on the line you're on, small print and all: same pattern, same replacement, same g. g& sends it to every line in the file, with one catch: it takes its pattern from your last search. Straight after the slip that's the slip's own pattern (a :s counts as a search), so it does what you expect; search for something else in between and g& replaces that instead. (Plain & also repeats the slip on this line, but in Vim it drops the small print and changes only the first match; Neovim maps & to :&&↵, so there it keeps it. :&&↵ means the same everywhere.)
rider = 1; rider++;log(rider, rider);free(rider, rider);courier = 1; courier++;log(rider, rider);free(rider, rider);courier = 1; courier++;log(courier, courier);free(rider, rider);courier = 1; courier++;log(courier, courier);free(courier, courier);g on line 1; :&&↵ sends it again on line 2, g and all; g& sends it to every line.Here, and there
Rename rider on the first line with the whole-word slip (:s/\<rider\>/courier/g). Then the same on line 2 and line 4 with :&&↵, leaving line 3 alone.
This exercise needs a keyboard. Read on, and play it at your computer.
Which pattern?
You send :s/a/x/g↵ on line 1, then search for b with /b↵, then press g&. What does the file say?
Every line
Rename on the first line with the whole-word slip, check it, then send it to the whole file with g&.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
A search in between
You sent the whole-word slip on line 1, then searched for zone to check something. g& would now rename every zone. Rename rider on the rest of the file anyway: :%&&↵ is the slip again on every line (%) with its own pattern and small print. Typing the slip out again works too.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Point first, then the slip
An empty pattern means the last thing you searched for. So put the cursor on a word, press * (it searches for exactly that whole word), then :%s//courier/g: no pattern to type, and riders and riderCount are safe because * only matches the whole word.
Point and rename
The cursor is on rider. *, then :%s//courier/g↵: the whole word only, everywhere.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Again, from memory
Press the keys.