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 --- README.md | 2 +- autoload/novim_mode.vim | 19 ++++++++++++++----- doc/novim_mode.txt | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0c99738..ae36a30 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ One further common problem is that `tmux` can change key combination behaviour, * `CTRL+N`: Open a new file. * `CTRL+O`: Open an existing file. * `CTRL+S`: Saves the current file. + * `CTRL+Q`: Quit Vim. * `CTRL+G`: Goto line. * `ALT+;` or `ALT+c`: Vim's command prompt. * `ALT+o`: Replaces native `CTRL+O` to give one-off Normal Mode commands. @@ -119,4 +120,3 @@ Lastly you can unmap a mapping using commands such as `nunmap`, `iunmap`, `sunma * In Neovim there seems to be a bug where only `SHIFT+TAB` and not `TAB` works for indenting during selection mode. * Mapping `` internally means mapping ``. This is a throwback to Vim's days as a pure terminal application. * `CTRL+BACKSPACE` internally represents ``, which can be annoying. Again this is a throwback to Vim's days as a pure terminal application. - 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() diff --git a/doc/novim_mode.txt b/doc/novim_mode.txt index ee277cd..e464937 100644 --- a/doc/novim_mode.txt +++ b/doc/novim_mode.txt @@ -76,6 +76,7 @@ General editor shortcuts * `CTRL+N`: Open a new file. * `CTRL+O`: Open an existing file. * `CTRL+S`: Saves the current file. + * `CTRL+Q`: Quit Vim. * `CTRL+G`: Goto line. * `ALT+;` or `ALT+c`: Vim command prompt. * `ALT+o`: Replaces native `CTRL+O` to give one-off Normal Mode commands. -- cgit v1.2.3-70-g09d2