I wish to close windows and wipe out the associated buffers with <c-w>q
but at the same time I want to prevent to quit Vim when there is only one window left.
My attempt is as follows:
vim9script
def QuitWindow()
# Close window and wipe buffer but prevent Vim to quit if one window is
# left.
if winnr('$') != 1
quit
endif
enddef
nnoremap <c-w>q <Cmd>call QuitWindow()<cr>
nnoremap <c-w><c-q> <Cmd>call QuitWindow()<cr>
but then QuitWindow()
is correctly not recognised and I am not sure how to do for recognising a function when it is defined in .vimrc
and is not defined as global.
Perhaps this is not the right direction for achieving my goal?
<C-w>q
and there's only one window… don't press<C-w>q
when there is only one window. Also, the RHS of a normal mode mapping is a normal mode macro: use:call …
or<Cmd>call …
.:help <Cmd>
.:help <Cmd>
.:help <ScriptCmd>
?