Force GVim to prompt before close
Putting the following in your vimrc could be used to completely disable the ZZ shortcut altogether:
nnoremap ZZ <Nop>
Or you could remap them to the standard behaviour of :q
:
if has("gui_running")
nnoremap ZZ :q
nnoremap :wq :q
endif
Call a function on ZZ
and if there is only one tab and window left, prompt whether to close or not (default is to close). See :help confirm()
.
nnoremap ZZ :call QuitPrompt()<cr>
fun! QuitPrompt()
if has("gui_running") && tabpagenr("$") == 1 && winnr("$") == 1
let choice = confirm("Close?", "&yes\n&no", 1)
if choice == 1 | wq | endif
else | wq | endif
endfun
Add this in your .vimrc:
set confirm