This is something I wanted when I first started using Vim, but I no longer do. From looking at your account, I can see you've been using Vim for several years, but for the benefit of other readers who are new users, I thought I'd explain why I no longer feel the need for this.
Vim offers several different methods for closing windows and buffers, and these have slightly different behaviours. In my use, I know what my goal is, and so I run whichever command that will achieve it.
:q This will close a window, and, if it is the last window, it will quit Vim. So if I don't want to quit Vim, I don't run this command!
:bd This will delete a buffer, and in doing so, it will close any window that is currently displaying that buffer. But if you run it when you only have one window open, then Vim will not quit, and instead, one of your hidden buffers will be displayed. If you don't have any other buffers open, then a new, empty buffer will be displayed.
:%bd If you don't want to switch to another existing buffer, but instead want to close all visible and hidden buffers and start editing a new empty buffer, then you can pass a
% range into the
:bd command, to tell it to delete all your buffers.
:enew If I only have one window open and I have some other hidden buffers that I don't want closed, then I will instead use this command to switch from my current buffer to a new empty one.
:close or Ctrl-Wc Close a window, but if there is only one window remaining, don't close it. For some reason I sometimes use Ctrl-Wc to close a window instead of
:q. It's not because of the difference in behaviour (if I only have one window open I don't ever use this command because I know it won't do anything!); it seems to be just what I feel like typing at the time.
So to address the actual question, when I only have one window open, I know in advance of running a command whether I want to:
- Start editing a new empty buffer, or
- Quit Vim.
For 2, I use
:q. For 1, I use
:bd, or occasionally