How do I hide a buffer from the buffer list without closing it?
Answer
:setlocal nobuflisted
Explanation
Setting nobuflisted removes a buffer from the :ls output and buffer-switching commands like :bnext/:bprev, while keeping it loaded and accessible. This is how plugins hide helper buffers, and you can use it for scratch buffers or temporary reference files.
How it works
:setlocal nobuflisted— hides buffer from:lsand:bnext:setlocal buflisted— shows buffer in the list again- The buffer remains loaded and accessible via
:buffer {name}or:b {number} :ls!(with bang) shows ALL buffers including unlisted ones
Example
" Hide the current buffer from the list
:setlocal nobuflisted
" Verify it's hidden
:ls " won't show this buffer
:ls! " shows it with a 'u' flag
:ls output: (buffer 3 hidden)
1 %a "main.py"
2 h "utils.py"
:ls! output: (buffer 3 visible with 'u')
1 %a "main.py"
2 h "utils.py"
3 u "scratch"
Tips
:bnextand:bprevskip unlisted buffers — clean buffer cycling- Plugins use this for file trees, terminals, help windows, etc.
- Combine with
buftype=nofilefor full scratch buffer behavior - Use in autocmds:
autocmd FileType qf setlocal nobuflisted