There's not really a great solution for that, as most of them have shortcomings.
You could try to
:set bufhidden=delete (see
'bufhidden' for more details.) This looks pretty close to what you want.
'bufhidden' is a setting that is local to buffer, so you would have to set it for every new buffer, or for the buffers you want to be ephemeral as you describe. You could potentially do that from an
autocmd or perhaps a few of them, depending on your criteria for which buffers should be deleted when hidden.
Also note that Vim documentation strongly recommends against using that option!
wipe is used changes in a buffer are lost without a warning. Also, these values may break autocommands that switch between buffers temporarily.
So that's probably a non-starter...
:set nobuflisted (see
'buflisted', in which case the buffer exists, only isn't listed in
It is also a setting local to a buffer, so you'd need an
autocmd to set it on new buffers.
This one doesn't seem to be as dangerous, and seems to almost do what you asked for. But this one will unlist even the current buffer, or buffers for the open windows, so this essentially makes sure
:ls will be always empty, which makes it useless, in which case are you really better off than leaving buffers around?
Finally, you can cleanup buffers after a large operation (say involving
:args or quickfix), once you're done and saved everything, you can use:
This will close all buffers and leave you with a new empty file to edit. (See documentation for
This might be an useful command once you're switching to something new and you want to be able to keep only a small handful of buffers around, so you can quickly switch between them using short substrings of their filenames, or
:bnext and friends.