Step 2 of 8

Selecting inside a selection

Selecting inside a selection

Copying a cursor line by line is fine for neighbouring lines. The command you will actually reach for most is s: select regex. It takes the current selection, looks for every match of a pattern inside it, and gives each match its own cursor.

The recipe is always the same:

  • make a selection that covers the text you care about — % for the whole buffer, x for a few lines, or any motion
  • press s and type a pattern; the matches light up as you type
  • hit Enter to keep them

From there, you’re back in normal mode with one cursor per match, and any command acts on all of them. Changing every match with c is the classic example, but d, y, i, a and the rest all work the same way.

Nothing matching? Escape in the prompt abandons the search and leaves your original selection alone.

Work through the checklist below to turn every TODO into DONE in one edit.

  1. Select the whole buffer with % Everything highlights when you press %.
  2. Select every TODO inside it with s Press s and type TODO — every match lights up with its own cursor.
  3. Change them all at once with c Hit Enter to close the prompt — the matches vanish when you press c.
  4. Type DONE, then hit Escape Every line should now start with DONE.
Select the whole buffer with % Everything highlights when you press %.

Next: Select every TODO inside it with s

Loading editor…