Instead I want it to close the files and open the default No Name
buffer. I sometimes accidentally close the last file and I have to restart gvim and cd to the proper directory.
put it in your $MYVIMRC
function! NumberOfWindows()
let i = 1
while winbufnr(i) != -1
let i = i+1
endwhile
return i - 1
endfunction
function! DonotQuitLastWindow()
if NumberOfWindows() != 1
let v:errmsg = ""
silent! quit
if v:errmsg != ""
"echohl ErrorMsg | echomsg v:errmsg | echohl NONE
"echoerr v:errmsg
echohl ErrorMsg | echo v:errmsg | echohl NONE
endif
else
echohl Error | echo "Can't quit the last window..." | echohl None
endif
endfunction
if has("gui_running")
cnoreabbrev <expr> q getcmdtype() == ":" && getcmdline() == 'q' ? 'call DonotQuitLastWindow()' : 'q'
cnoreabbrev <expr> qa getcmdtype() == ":" && getcmdline() == 'qa' ? 'call DonotQuitLastWindow()' : 'qa'
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With