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}withhiddentemporarily enabled (e.g.,:hide edit other.py)- The buffer appears in
:lswith anhflag 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 hiddenmakes ALL buffer-switching commands behave like:hide— you can:bnextaway from modified buffers without warnings:lsshowshnext to hidden buffers and+for modified ones:unhide/:ballopens all hidden buffers in splits:hideis the safest way to close a window when you are not sure if changes are saved — nothing is lost