From 7b7e91cba36e3b63d4917186bdeb16e3c394f417 Mon Sep 17 00:00:00 2001 From: j-james Date: Thu, 27 May 2021 21:49:03 -0700 Subject: Prompt when closing or quitting w/ unsaved changes --- autoload/novim_mode.vim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'autoload') diff --git a/autoload/novim_mode.vim b/autoload/novim_mode.vim index 9d09d58..2b66f03 100644 --- a/autoload/novim_mode.vim +++ b/autoload/novim_mode.vim @@ -291,11 +291,17 @@ function! novim_mode#ClosePane() " Close any quickfix lists on screen. exe "cclose" + let l:check = execute(":ls") if s:CountListedBuffers() > 1 " By default if the buffer is the only one on screen, closing it closes the " tab/window. So this little trick does a switch to the next buffer, " then closes the previous buffer. exe "bp\|bd #" + elseif l:check =~ "%a +" + let l:confirmed = confirm('There are unsaved changes. Close anyway?', "&Yes\n&No", 2) + if l:confirmed == 1 + quit! + endif else quit endif @@ -304,12 +310,15 @@ function! novim_mode#ClosePane() endif endfunction -" TODO: Mention any unsaved buffers function! novim_mode#ExitVim() - let l:confirmed = confirm('Do you really want to quit Vim?', "&Yes\n&No", 2) - if l:confirmed == 1 - quitall! - endif + let l:check = execute(":ls") + if l:check =~ "+" + let l:confirmed = confirm('There are unsaved changes. Quit anyway?', "&Yes\n&No", 2) + if l:confirmed == 1 + quitall! + endif + else + quitall endfunction function! novim_mode#GotoLine() -- cgit v1.2.3-70-g09d2