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

How do I close all windows except the current one?

Answer

:only

Explanation

The :only command closes every window in the current tab page except the one your cursor is in. It is the fastest way to declutter your screen when you have accumulated too many splits and want to focus on a single file.

How it works

  • :only (or :on for short) closes all other windows in the current tab
  • The keyboard shortcut is <C-w>o (Ctrl+w then o)
  • Buffers in the closed windows remain loaded in memory — they are not deleted, just hidden
  • If any of the other windows contain unsaved changes, Vim will refuse to close them unless you use :only! to force it

Example

You have four splits open after a debugging session:

┌──────────┬──────────┐
│  main.go │  test.go │
├──────────┼──────────┤
│  log.txt │ utils.go │
│ (active) │          │
└──────────┴──────────┘

With the cursor in log.txt, pressing <C-w>o or running :only closes the other three windows. log.txt expands to fill the entire screen. The other files are still loaded and accessible via :ls and :buffer.

Tips

  • Use <C-w>o as the normal-mode shortcut — it is faster to type than :only
  • Use :only! to force-close windows with unsaved changes (the buffers become hidden with unsaved modifications)
  • Use <C-w>c or :close to close just the current window instead of all the others
  • Use :qa to quit all windows and exit Vim entirely
  • Use :tabonly to close all other tabs while keeping the current tab
  • After running :only, you can reopen any buffer with :split or :vsplit followed by :buffer <name>
  • This command only affects the current tab page — windows in other tabs are not touched

Next

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