Closing and Quitting Windows

There are four different ways to close a window that are specific to window editing: quit, close, hide, and close all others.

^Wq (or ^W^Q, or :quit) is really just a window version of the:quit command. In its simplest form (i.e., a single session edit with only one window), it behaves exactly like vi’s :quit command. If the hidden option is set and the current window is the last window on the screen referencing that file, the window is closed but the file buffer is retained (it can be retrieved) and hidden. In other words, Vim is still storing the file and you can return to editing it later. If hidden is not set, the window is the last one referencing that file, and there are unsaved changes in the current window buffer, the command fails in order to avoid losing your changes. But if some other window displays the file, the current window closes.

^Wc (or :close[!]) closes the current window. If the hidden option is set and this is the last window referencing this file, Vim closes the window and the buffer is hidden. If this window is on a tab page and is the last window for that tab page, the window and the tab page are closed. As long as you don’t use the ! modifier, this command will not abandon any file with unsaved changes. The ! modifier tells Vim to close the current window unconditionally.

Note

Note that this command does not use ^W^C, because Vim uses ^C to cancel commands. Therefore, if you try to use ^W^C, the ^C simply cancels the command.

Similarly, ...

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.