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

How do I close a window but keep its buffer loaded and available?

Answer

:hide

Explanation

:hide closes the current window without unloading or deleting its buffer. The buffer stays in the buffer list (visible in :ls) and retains its undo history, marks, and unsaved changes. You can reopen it anytime with :buffer {name} or :sb {name}. This is different from :close, which may warn about unsaved changes.

How it works

  • :hide — close the current window; the buffer becomes hidden
  • :hide {command} — run {command} with hidden temporarily enabled (e.g., :hide edit other.py)
  • The buffer appears in :ls with an h flag indicating it is hidden
  • Unsaved changes are preserved — no warning, no data loss

:hide vs :close vs :quit

Command Window Buffer Unsaved changes
:hide Closes Stays loaded (hidden) Preserved silently
:close Closes Stays loaded Warns if modified (unless hidden is set)
:quit Closes May unload Warns if modified
:bdelete Closes Removed from list Warns if modified

Example

You have three splits open. You want to temporarily focus on one file:

:hide    " close current split, buffer stays available
:hide    " close another split
" Now you have one window. Later:
:sb main.py    " reopen the hidden buffer in a split

Tips

  • :set hidden makes ALL buffer-switching commands behave like :hide — you can :bnext away from modified buffers without warnings
  • :ls shows h next to hidden buffers and + for modified ones
  • :unhide / :ball opens all hidden buffers in splits
  • :hide is the safest way to close a window when you are not sure if changes are saved — nothing is lost

Next

How do I run a search and replace only within a visually selected region?