Step 2 of 9

12. Windows

Commands for opening new windows

There are lots of ways to open a new window in Vim. Most of the time it involves splitting the current window in two — either horizontally (two windows on top of each other) or vertically (two windows side-by-side). This is why you’ll often hear windows called “splits” in the community.

The simplest ways in are the split commands: :split (horizontal) and :vsplit (vertical). Both accept a filename, which tells Vim to:

  1. Load the given file into a new buffer.
  2. Split the current window in two.
  3. Open the buffer in the new window.

Alongside the editor’s exercise.txt there are three other files: a.txt, b.txt, and c.txt. Work through the checklist to open each one in a split of its own.

  1. Open a.txt in a horizontal split The new window will open above, with a.txt loaded inside — type :split a.txt and hit Enter.
  2. Open b.txt in a vertical split This one opens side-by-side — type :vsplit b.txt and hit Enter.
  3. Open c.txt in one more split Type :split c.txt and hit Enter — four windows on one screen!
Open a.txt in a horizontal split The new window will open above, with a.txt loaded inside — type :split a.txt and hit Enter.

Next: Open b.txt in a vertical split

Loading editor…