Recipes
Outcome: five whole jobs, each done
with moves from earlier chapters and
nothing else. A recipe here is a
composition, not a new feature: every
key appears in the chapter that
introduced it. Recipes 1, 2, 4 and 5
were run in the lab end to end as
written; recipe 3 composes two
separate lab runs (a pattern split,
and a surround) whose combination
follows the rule that verbs act on all
selections at once. If one surprises
you, the chapters are the explanation
and u is the exit.
Rename a word in the whole file
Chapters 5 and 6. You have used a wrong name eleven times in one file and the right name in none. (For a name whose meaning matters — a variable, a function — prefer the server rename of chapter 7; this recipe is for text: labels, headings, words.)
%— select the whole file.s, type the word, Enter — one selection per occurrence.c, type the new word, Esc.:w.
The lab's version turned three lines
of apple into three of fruit
(helix-lab/transcripts/t06-multiple-cursors.txt);
the pattern can be a regular
expression, so punctuation and spacing
around the word are yours to include
or exclude deliberately.
Fix a list so every line matches
Chapter 6. Three lines each hold a different word and all should hold the same one — a packing list, a rota, a set of repeated labels.
- Cursor on the first line.
Conce per further line — a cursor on each, same column (3/3 selsfor three).e— each cursor selects its own line's word, whatever its length.c, type the word, Esc.
Remember the order — duplicate first,
then extend. Starting from whole-line
selections (x) and changing them
together eats the newlines and merges
the lines; chapter 13 has the lab's
exhibit.
Wrap every match in brackets
Chapters 5 and 6. Every occurrence of a term should gain parentheses — terms in a glossary, codes in a table.
%, thens, type the term, Enter — every match selected.ms(— match-mode surround, open bracket: each selection gains the pair around it.
The lab wrapped a single selected word
this way (The( quick) brown...,
transcript t05); the same two keys
after a split act on every match at
once, because surround is a verb and
verbs act on all selections.
Empty out a function, keep its shape
Chapter 5. A function needs rewriting from the inside: signature and callers stay, body goes.
- Cursor anywhere inside the function.
mif— match, inside, function: the whole body is one selection.d— delete. The definition line remains, with an empty indented body line beneath it.ito enter Insert mode there, and type the new body at your leisure.
Tree-sitter found the boundaries, so this works the same in a three-line helper and a sixty-line monster, and in any language whose queries the health table ticks.
Walk the errors, one by one
Chapter 7. A file the language server has opinions about, and you want them in order, at the scene of each.
Space d— the diagnostics picker.- Read the list: severity, source,
message. (The lab's read:
ERROR pyflakes — undefined name 'mesage'.) - Enter on the first entry — you are standing on the offending name.
- Fix it —
eto select a mistyped word,cto retype it, orSpace rif it is a symbol to rename properly. - Repeat from step 1; the picker re-reads the server's current account each time it opens.
No build ran, no test ran; the server did the reading. When the picker is empty, the file is — by the server's lights, which are meaning-level lights — clean.