How do I close the current window in Vim?
Answer
<C-w>c
Explanation
The <C-w>c (Ctrl+w then c) command closes the current window without closing the buffer it contains. If the buffer is displayed in another window, it remains visible there. If it is the last window, Vim will refuse to close it — use :q instead.
How it works
<C-w>is the window command prefixcstands for "close"- The buffer remains loaded in memory and can be accessed again with
:bufferor:ls
Compared to other close commands
<C-w>cor:close— closes the current window but keeps the buffer loaded:q— quits the current window; if it is the last window, quits Vim entirely:bd— closes the buffer and any window displaying it<C-w>oor:only— closes all other windows, keeping only the current one
Example
You have two horizontal splits open. The cursor is in the bottom split. Pressing <C-w>c closes the bottom split, and the top split expands to fill the full screen. The buffer from the closed window is still loaded and can be reopened.
Tips
- Use
:closeas the Ex command equivalent of<C-w>c - Use
<C-w>qto quit the current window (like:q— exits Vim if it is the last window) - Use
<C-w>oor:onlyto close every window except the current one - Use
:qato quit all windows and exit Vim - If you have unsaved changes, Vim will warn you and refuse to close — use
:q!to force quit without saving, or:wto save first - Use
ZZas a shortcut for:wq(save and close the current window)