blob: 540031b75bde3a92247173fa7acc5cf45ca6ce95 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
"
" 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,
" while 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
"
if exists('loaded_insert_cancel') || &compatible || v:version < 700
finish
endif
let loaded_insert_cancel = 1
" Each time the cursor moves in normal mode, cache the current change number
augroup insert_cancel
autocmd!
autocmd CursorMoved *
\ let b:insert_cancel_changenr = changenr()
augroup END
" Undo any changes if they exceed the cached number on insert map key press
inoremap <expr> <Plug>(InsertCancel)
\ changenr() > b:insert_cancel_changenr ? "\<Esc>u" : "\<Esc>"
|