I use the following script with assumption:
nnoremap <nowait><silent><expr> ∑ "(YOUR_SHORT_CUT)
\ (&filetype=="fern" <bar><bar> &filetype=="startify"
\ <bar><bar> len(getbufinfo({'buflisted':1}))==1 && &filetype=="")? ":q<CR>":
\ (winnr('$')==1)? ":bd<CR>":
\ (&filetype=="")? ":bd<CR>": ":enew<CR>"
Assumption: Every time I do :vsp
or :sp
, it should create a new [No Name]-buffer, i.e.:
nnoremap <nowait><expr> <C-W><C-H>
\ ":vsp<CR>".(&filetype==""? ":enew<CR>": "")
nnoremap <nowait><expr> <C-W><C-J>
\ ":sp<CR><C-W><C-J>".(&filetype==""? ":enew<CR>": "")
nnoremap <nowait><expr> <C-W><C-K>
\ ":sp<CR>".(&filetype==""? ":enew<CR>": "")
nnoremap <nowait><expr> <C-W><C-L>
\ ":vsp<CR><C-W><C-L>".(&filetype==""? ":enew<CR>": "")
The scripts can:
If the filetype is MENU / DRAWER: since no buffer for them, use :q
.
If it is the last [No Name]-buffer: at this situation we want to quit vim, use :q
.
If only one window left: we can delete the buffer without destroy the window-layout, use :bd
.
If there are many windows:
- If it is [No Name]-buffer, by assumption every split create a new [No Name] buffer, so no need to worry about closing multiple [No Name]-buffers at the same time to destroy the layout, use
:bd
.
- Otherwise, it's the buffer with which you're done, just
:enew
and keep the buffer you're done, so no possible to destroy layout(s) when it might also on other split(s).
In short: we only :bd
when there is no layout(only one window left) anymore.
Feature: By holding ∑
you will close all of them and exit Vim.
Example:
