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

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 :ls and :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

  • :bnext and :bprev skip unlisted buffers — clean buffer cycling
  • Plugins use this for file trees, terminals, help windows, etc.
  • Combine with buftype=nofile for full scratch buffer behavior
  • Use in autocmds: autocmd FileType qf setlocal nobuflisted

Next

How do I return to normal mode from absolutely any mode in Vim?