vimtricks.wiki Concise Vim tricks, one at a time.

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 prefix
  • c stands for "close"
  • The buffer remains loaded in memory and can be accessed again with :buffer or :ls

Compared to other close commands

  • <C-w>c or :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>o or :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 :close as the Ex command equivalent of <C-w>c
  • Use <C-w>q to quit the current window (like :q — exits Vim if it is the last window)
  • Use <C-w>o or :only to close every window except the current one
  • Use :qa to 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 :w to save first
  • Use ZZ as a shortcut for :wq (save and close the current window)

Next

How do I edit multiple lines at once using multiple cursors in Vim?