aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-28 22:45:00 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-28 22:45:00 +1200
commite8f1153d387782d966b8a07b7b91efe5ddeff42e (patch)
tree2cd44d208efe8ac0065ff15f87b8412a7518b8cf
parentMerge branch 'release/v4.0.0' (diff)
parentBump VERSION (diff)
downloadvim-insert-cancel-e8f1153d387782d966b8a07b7b91efe5ddeff42e.tar.gz
vim-insert-cancel-e8f1153d387782d966b8a07b7b91efe5ddeff42e.zip
Merge branch 'release/v5.0.0'v5.0.0
* release/v5.0.0: Completely overhaul, losing autoload
-rw-r--r--README.md8
-rw-r--r--VERSION2
-rw-r--r--autoload/insert_cancel.vim22
-rw-r--r--doc/insert_cancel.txt16
-rw-r--r--plugin/insert_cancel.vim22
5 files changed, 20 insertions, 50 deletions
diff --git a/README.md b/README.md
index 4efa5dd..b0e07eb 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
insert\_cancel.vim
==================
-This plugin provides a mapping target to cancel an insert operation. It leaves
-insert mode normally, firing `InsertLeave`, and then runs `:undo` if the buffer
-was changed by the insert. This is intended as a remap of Ctrl-C in insert
-mode.
+This small plugin provides a mapping in insert mode to cancel the current
+insert operation by undoing the last change upon insert exit, if a change to
+the buffer was made during insert mode, without firing `InsertLeave`. This is
+intended for remapping Ctrl-C in insert mode to do something more useful.
License
-------
diff --git a/VERSION b/VERSION
index fcdb2e1..0062ac9 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-4.0.0
+5.0.0
diff --git a/autoload/insert_cancel.vim b/autoload/insert_cancel.vim
deleted file mode 100644
index 74af060..0000000
--- a/autoload/insert_cancel.vim
+++ /dev/null
@@ -1,22 +0,0 @@
-" On entering insert mode, reset the changed flag and check for a new round of
-" changes since insert mode was opened
-function! insert_cancel#Enter() abort
- let b:insert_cancel_changed = 0
- call insert_cancel#Check()
-endfunction
-
-" On leaving insert mode, whether normally or via <Plug>(InsertCancel), check
-" if changenr() exceeds the last time we cached it, and flag that a change has
-" taken place if it did
-function! insert_cancel#Check() abort
- if changenr() > b:insert_cancel_changenr
- let b:insert_cancel_changed = 1
- endif
-endfunction
-
-" On cancelling insert mode, if we think we made a change, undo it
-function! insert_cancel#Cancel() abort
- if get(b:, 'insert_cancel_changed', 0)
- silent undo
- endif
-endfunction
diff --git a/doc/insert_cancel.txt b/doc/insert_cancel.txt
index 9e0deda..5c628be 100644
--- a/doc/insert_cancel.txt
+++ b/doc/insert_cancel.txt
@@ -1,11 +1,11 @@
-*insert_cancel.txt* For Vim version 7.0 Last change: 2019 May 25
+*insert_cancel.txt* For Vim version 7.0 Last change: 2019 May 28
DESCRIPTION *insert_cancel*
-This plugin provides a mapping target to cancel an insert operation. It
-leaves insert mode normally, firing |InsertLeave|, and then runs |:undo| if
-the buffer was changed by the insert. This is intended as a remap of
-|i_CTRL-C|.
+This small plugin provides a mapping in insert mode to cancel the current
+insert operation by undoing the last change upon insert exit, if a change to
+the buffer was made during insert mode, without firing InsertLeave. This is
+intended for remapping |i_CTRL-C| to do something more useful.
REQUIREMENTS *insert_cancel-requirements*
@@ -20,11 +20,9 @@ example:
>
imap <C-C> <Plug>(InsertCancel)
<
-ISSUES *insert_cancel-issues*
+LIMITATIONS *insert_cancel-limitations*
-It doesn't work at all in paste mode, in the same way as any other mapping, so
-you can't cancel an insert operation while pasting. You might consider this a
-feature.
+It doesn't work in paste mode, much the same as any other mapping.
AUTHOR *insert_cancel-author*
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim
index f722ac8..f0d8443 100644
--- a/plugin/insert_cancel.vim
+++ b/plugin/insert_cancel.vim
@@ -1,9 +1,8 @@
"
-" insert_cancel.vim: Cancel the current insert operation by undoing the last
-" change upon insert exit, if we made a change; intended for remapping
-" insert-mode Ctrl-C to do something useful.
-"
-" This was *way* harder to figure out than it looks.
+" insert_cancel.vim: Insert mode mapping to cancel the current insert
+" operation by undoing the last change upon insert exit, if we made a change,
+" without firing InsertLeave. This is intended for remapping Ctrl-C in insert
+" mode to do something more useful.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -13,18 +12,13 @@ if exists('loaded_insert_cancel') || &compatible || v:version < 700
endif
let loaded_insert_cancel = 1
-" Set up the hooks described for the functions above, if Vim is new enough to
-" support all the hooks required
+" Each time the cursor moves in normal mode, cache the current change number
augroup insert_cancel
autocmd!
- autocmd InsertEnter *
- \ call insert_cancel#Enter()
- autocmd InsertLeave *
- \ call insert_cancel#Check()
autocmd CursorMoved *
\ let b:insert_cancel_changenr = changenr()
augroup END
-" Mapping that exits insert mode normally and checks for a change to undo
-inoremap <silent> <Plug>(InsertCancel)
- \ <Esc>:<C-U>call insert_cancel#Cancel()<CR>
+" Undo any changes if they exceed the cached number on insert map key press
+inoremap <expr> <Plug>(InsertCancel)
+ \ changenr() > b:insert_cancel_changenr ? "\<C-C>u" : "\<C-C>"