diff options
Diffstat (limited to 'plugin/insert_cancel.vim')
-rw-r--r-- | plugin/insert_cancel.vim | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim index 7566fee..61d0b49 100644 --- a/plugin/insert_cancel.vim +++ b/plugin/insert_cancel.vim @@ -1,7 +1,7 @@ " " 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. +" insert-mode Ctrl-C to do something useful. " " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself @@ -17,16 +17,24 @@ let g:loaded_insert_cancel = 1 " Initialise s:changedtick so vint understands let s:changedtick = 0 -" InsertEnter is only available from Vim 7 -if has('autocmd') && v:version >= 700 +" Set up an appropriate hook to track b:changedtick before we hit InsertLeave +if has('autocmd') augroup insert_cancel autocmd! - autocmd InsertEnter * - \ let s:changedtick = b:changedtick + + " Ideal; only runs when the text actually changes + if v:version > 703 || v:version == 703 && has('patch867') + autocmd TextChanged * let s:changedtick = b:changedtick + + " Workable but wasteful and not quite as correct; updates every move + elseif v:version >= 700 + autocmd CursorMoved * let s:changedtick = b:changedtick + endif + augroup END endif -" Try to figure out whether we made a change to undo, undo it if so +" Try hard to figure out whether we made a change to undo, and undo it if so function! s:InsertCancel() if !&modified return |