diff options
Diffstat (limited to 'plugin/insert_cancel.vim')
-rw-r--r-- | plugin/insert_cancel.vim | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim index 8ad47e5..a4595f9 100644 --- a/plugin/insert_cancel.vim +++ b/plugin/insert_cancel.vim @@ -11,7 +11,7 @@ if exists('loaded_insert_cancel') || &compatible finish endif -if v:version < 600 +if v:version < 700 finish endif let loaded_insert_cancel = 1 @@ -34,41 +34,25 @@ endfunction " On cancelling insert mode, if we think we made a change, undo it function! s:Cancel() - - " The flag exists, if it's on, undo - if exists('b:insert_cancel_changed') - if b:insert_cancel_changed - silent undo - endif - - " The flag didn't exist, fall back to marks; if the line number or column - " number of the marks for the last changed text aren't exactly equal, that - " suggests we changed something; undo it - elseif line("'[") != line("']") || col("'[") != col("']") + if get(b:, 'insert_cancel_changed', 0) silent undo endif - - " Redraw the screen to avoid bug with vestigial 'showmode' display - redraw! - endfunction " Set up the hooks described for the functions above, if Vim is new enough to " support all the hooks required -if has('autocmd') && v:version >= 700 - augroup insert_cancel - autocmd! +augroup insert_cancel + autocmd! - " On buffer edit and cursor move, cache the current change number - autocmd BufEnter,CursorMoved * - \ let b:insert_cancel_changenr = changenr() + " On buffer edit and cursor move, cache the current change number + autocmd BufEnter,CursorMoved * + \ let b:insert_cancel_changenr = changenr() - " Function wrappers for entering and leaving insert mode - autocmd InsertEnter * call s:Enter() - autocmd InsertLeave * call s:Check() + " Function wrappers for entering and leaving insert mode + autocmd InsertEnter * call s:Enter() + autocmd InsertLeave * call s:Check() - augroup END -endif +augroup END " Mapping that exits insert mode normally and checks for a change to undo inoremap <silent> <Plug>(InsertCancel) |