Buffers and Their Interaction with Windows

Vim uses buffers as containers for work. Understanding buffers completely is an acquired skill; there are many commands for manipulating and navigating them. However, it is worthwhile to familiarize yourself with some of the buffer basics and understand how and why they exist throughout a Vim session.

A good starting point is to open up a few windows editing different files. For example, start Vim by opening file1. Then, within the session, issue :split file2 and then :split file3. You should now have three open files in three separate Vim windows.

Now use the commands :ls, :files, or :buffers to list the buffers. You should see three lines, each numbered and including the filenames, along with additional information. These are Vim’s buffers for this session. There is one buffer for each file and each buffer has a unique, nonchanging associated number. In this example, file1 is in buffer 1, file2 is in buffer 2, etc.

Additional information on each buffer can be displayed if you append an exclamation point (!) after any of the commands.

To the right of each buffer number are status flags. These flags describe the buffers as shown in Table 11-6.

Table 11-6. Status flags describing buffers
CodeDescription
u

Unlisted buffer. This buffer is not listed unless you use the ! modifier. To see an example of an unlisted buffer, type :help. Vim splits the current window to include a new window in which the built-in help appears. The plain :ls command will ...

Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.