aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorj-james2021-05-28 04:49:03 +0000
committerThomas Buckley-Houston2021-05-28 23:57:34 +0000
commit7b7e91cba36e3b63d4917186bdeb16e3c394f417 (patch)
tree3fbb209f25c3758e18df75e500804f9686cf950e
parentf596f02da0e7546cae9babad11922b5c4af91381 (diff)
Prompt when closing or quitting w/ unsaved changes
-rw-r--r--README.md2
-rw-r--r--autoload/novim_mode.vim19
-rw-r--r--doc/novim_mode.txt1
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 `<CTRL+M>` internally means mapping `<RETURN>`. This is a throwback to Vim's days as a pure terminal application.
* `CTRL+BACKSPACE` internally represents `<CTRL+H>`, 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.