diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-28 22:45:00 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-28 22:45:00 +1200 |
commit | e8f1153d387782d966b8a07b7b91efe5ddeff42e (patch) | |
tree | 2cd44d208efe8ac0065ff15f87b8412a7518b8cf /plugin/insert_cancel.vim | |
parent | Merge branch 'release/v4.0.0' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-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
Diffstat (limited to 'plugin/insert_cancel.vim')
-rw-r--r-- | plugin/insert_cancel.vim | 22 |
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>" |