Windows are a viewport into a buffer
Before we dive in, I want to add a small warning: Vim’s system of buffers, windows, and tabs is probably quite different to what you’re used to in other text editors. But as you learn more, you’ll realise that Vim does it better. It’s well worth learning this stuff.
A brief word to the wise: try to forget what you already know about how files/windows/tabs work in your current text editor — trying to reconcile this with what Vim offers will make things harder!
Recall: in the last lesson we learned that a buffer is the in-memory text of a file. Vim lets us have multiple buffers open simultaneously, which allows us to work on multiple files in the same editing session.
Closely related to buffers is the idea of windows. A window is a viewport into a single buffer. It’s the “thing” that we’re looking through to see the contents of our file. If you can see text on the screen — congratulations! You’re looking at a buffer through a window.
Up until now, we’ve been working with just one window that fills up the whole screen — but we aren’t limited to this. Vim lets us divide up the available screen space into many windows, each one peering into a different buffer. You can use this to keep multiple files open on the screen at the same time!
As our first step, let’s try something simple: opening an existing file on disk in a new (horizontally split) window.
In the editor, the file that’s currently open is called demo. There is another file on disk called myfile. To open it in a split, type :split myfile. You should see the two files open at the same time in two windows — one on top of the other!