Step 1 of 6

Working with multiple files

Working with multiple files

So far in the course, we’ve used Helix to edit just one file. This is fine for learning the basics of how Helix works, but in real life this is quite limiting. Most text editing tasks require us to work with multiple files at once — programmers and software engineers, for example, usually end up working across multiple source files in the same editing session.

Helix has support for editing multiple files in the same session with buffers and windows. In this lesson, we’re going to focus on buffers. These are a prerequisite to understanding what windows are and how they work. In essence, a buffer is the in-memory text of a file — a file loaded into Helix for editing. You can make changes to the buffer, and the original file on disk will remain untouched until you decide to write. Strictly speaking, buffers don’t need to have a corresponding file on disk, but most of the time they do.

Helix lets us have multiple buffers open at the same time, which corresponds to us being able to modify multiple files in the same editing session.

In the editor, the file that’s currently open is called exercise.txt — you can see its name in the statusline at the bottom. There’s one other file alongside it, called myfile.

The checklist starts with a warm-up from lesson 11. Then open myfile with the :e command, and hop between the two buffers with gp and gn — short for go previous and go next.

  1. Give every file in the buffer its own cursor Warm-up from lesson 11 — select everything, then pick out a pattern inside it.
  2. Collapse back to a single cursor Lesson 11 — press Enter to accept the matches first, then drop the extra cursors.
  3. Open myfile with :e Type :e myfile — Tab completes the name — and press Enter.
  4. Go back with gp Type gp to return to the previous buffer.
  5. Jump forward again with gn Type gn to go to the next buffer.
Give every file in the buffer its own cursor Warm-up from lesson 11 — select everything, then pick out a pattern inside it.

Next: Collapse back to a single cursor

Loading editor…