vim: Part 2: Buffers, Windows, Tabs

In Part 1 we learnt about buffers and how to move between them and how to view all buffers as windows in VIM.

Here is a recap of the terms buffers, windows, and tabs.

  • buffer is the in-memory text of the file that was opened using vim. It may be visible or hidden. It is identified by a buffer number and has flags to indicate whether it is current, has been modified or not etc.
  • window is a viewport on a buffer whereas
  • tab is a collection of windows

Let’s look at a couple ways of dividing the screen to windows showing same of different files for editing in VIM.

vim -o file1 file2 file3 will open the 3 files in windows laid out horizontally. If you was the screen split into vertical windows then use vim -O file1 file2 file3

One could also use the command :new to open a blank window or :new file4 to open file4 in a new window that split the screen horizontally or :vnew file4 to split the current screen vertically

Go ahead and try it now. Play with the two ways of creating windows.

CTRL-W c to close the window where the cursor is positioned.

Moving to a different window is as simples as using CTRL-W arrow-keys

One can also convert all existing windows to tabs using CTRL-W T

Explore what happens when you start vim with multiple filenames as argument but no -o or -O switch. Check buffers using :ls and see if you can covert the buffers to windows and then to tabs.