Working with multiple files
So far in the course, we’ve used Vim to edit just one file. This is fine for learning the basics of how Vim 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.
Vim 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 Vim, a buffer can be thought of as the in-memory text of a file — in essence, a file loaded into Vim 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.
Vim 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.
Work through the checklist below: open myfile with the :e command, then hop between the two buffers with :bp and :bn — short for buffer previous and buffer next.