Step 3 of 8

Acting on every matching line

Acting on every matching line

Vim has a famous command for this job: :g/pattern/d deletes every line matching a pattern. Helix has no :g. Instead, you build the same thing out of pieces you already know, and you get to see the lines before they go.

The trick is that s selects the match, not the line. x fixes that: it grows each selection to cover its whole line, including the line break. So the Helix spelling of “delete every line matching HAYSTACK” is:

  • % to select the whole buffer
  • s, HAYSTACK, Enter to put a cursor on every match
  • x to grow each cursor into its full line
  • d to delete them

Four keys, and you get to check the highlights between each one. Swap the d for y and you’ve yanked every matching line instead; swap it for c and you’re rewriting them.

Work through the checklist below to clear the haystack.

  1. Select the whole buffer with % Everything highlights when you press %.
  2. Select every HAYSTACK with s Press s and type HAYSTACK — every match lights up with its own cursor.
  3. Grow each selection to its whole line with x Hit Enter to close the prompt — each line fills end to end when you press x.
  4. Delete them all with d Only the keep lines are left once you press d.
Select the whole buffer with % Everything highlights when you press %.

Next: Select every HAYSTACK with s

Loading editor…