Step 4 of 9

12. Windows

Closing windows

When you’re done with a window, close it with :q or :close.

:q is the same command you use to quit Vim — but when more than one window is open, it only quits the current window. Vim itself exits only when the last remaining window gets a :q.

:close does almost the same thing — the only real difference is that it won’t try to quit Vim when it’s the last window.

There are three files alongside the editor’s exercise.txt: foo.txt, bar.txt, and baz.txt. Work through the checklist: open them in splits, then practice closing windows both ways.

  1. Open foo.txt in a split Type :split foo.txt and hit Enter.
  2. Open bar.txt in a vertical split Type :vsplit bar.txt and hit Enter.
  3. Open baz.txt in one more split Four windows after this one — time to start closing them! Type :split baz.txt and hit Enter.
  4. Close the current window with :close The window will disappear, but Vim keeps running — type :close and hit Enter.
  5. Close another one with :q With windows still open, :q only quits the current one — type :q and hit Enter.
Open foo.txt in a split Type :split foo.txt and hit Enter.

Next: Open bar.txt in a vertical split

Loading editor…