Step 1 of 7

Macros are incredibly powerful

Macros are incredibly powerful

Macros are definitely up there among Helix’s most powerful features. The core problem that macros are trying to solve is that nobody likes making repetitive edits — it’s boring, error prone, and can take a very long time. Macros help us here by automating away routine edits, minimizing legwork.

The great thing about them is that they’re conceptually very simple, and we don’t have to learn very many new concepts to start using them effectively.

Helix’s macro functionality lets us record a sequence of keystrokes and replay them back at will. You can capture complex editing jobs with a macro, and replay it on demand to repeat the edit.

First, let’s learn how to record a macro. To start recording, hit Q (capital) in normal mode. Helix tells you it’s recording in two places: a Recording to register [@] message in the statusline, and a small [@] flag in the bottom-right corner that stays put for as long as the recording runs.

Once you’ve started recording, start editing. Your keystrokes will be stored inside the macro and you’ll be able to replay them later. Once you’ve finished with your edit, hit Q again to stop recording.

Let’s try it in the editor — the checklist starts with a warm-up from lessons 3 and 15. There’s a little TODO list in the buffer; start recording with Q, mark the first item as done, and hit Q again to stop. We’ll learn how to replay this kind of macro in the next section.

  1. Jump to the last line Warm-up from lesson 3 — the jump to the end of the file.
  2. Jump back to where you were Lesson 15 — the jumplist remembers the spot you left.
  3. Start recording with Q Start recording — the statusline says Recording to register [@].
  4. Fix the first line while recording Change the first word to DONE, inside the recording, and return to normal mode.
  5. Stop recording Stop recording — the [@] flag disappears.
Jump to the last line Warm-up from lesson 3 — the jump to the end of the file.

Next: Jump back to where you were

Loading editor…