aboutsummaryrefslogtreecommitdiff
path: root/plugin/insert_cancel.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/insert_cancel.vim')
-rw-r--r--plugin/insert_cancel.vim22
1 files changed, 8 insertions, 14 deletions
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>"