diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-22 22:37:23 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-22 22:37:23 +1200 |
commit | b2d05a24bd541ca32ad77b41c07c13c25528dd6e (patch) | |
tree | 6884508e9da993296c267474e06877875df9aa9f /autoload | |
parent | Merge branch 'release/v0.2.0' into develop (diff) | |
download | vim-paste-insert-b2d05a24bd541ca32ad77b41c07c13c25528dd6e.tar.gz vim-paste-insert-b2d05a24bd541ca32ad77b41c07c13c25528dd6e.zip |
Support mapping cancel keys, add Esc as default
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/paste_insert.vim | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/autoload/paste_insert.vim b/autoload/paste_insert.vim index 277f333..6068b51 100644 --- a/autoload/paste_insert.vim +++ b/autoload/paste_insert.vim @@ -43,29 +43,39 @@ function! paste_insert#() abort endfunction -" Key that cancels the pending paste in normal mode, defaults to CTRL-C -let s:cancel = get(g:, 'paste_insert_cancel', '<C-C>') +" Keys that cancel the pending paste in normal mode, defaults to Ctrl-C and +" Escape +let s:cancel = get(g:, 'paste_insert_cancel', ['<C-C>', '<Esc>']) -" Start the paste: save cancel key's prior function, remap it, set 'paste' +" Cache for the prior functions of those keys, in case the user has already +" mapped them +let s:maparg = {} + +" Start the paste: save each cancel key's prior function, remap it, set +" 'paste' function! s:Start() abort - let s:maparg = maparg(s:cancel) - let command = join([ - \ 'nnoremap' - \,s:cancel - \,':<C-U>doautocmd paste_insert User Cancel<CR>' - \]) - execute command + for key in s:cancel + let s:maparg[key] = maparg(key) + let command = join([ + \ 'nnoremap' + \,key + \,':<C-U>doautocmd paste_insert User Cancel<CR>' + \]) + execute command + endfor set paste endfunction " Stop the paste: unset 'paste', restore prior function of cancel key function! s:Stop() abort set nopaste - let command = join( - \ s:maparg !=# '' - \ ? ['nnoremap', s:cancel, s:maparg] - \ : ['nunmap', s:cancel] - \) - execute command - unlet s:maparg + for key in s:cancel + let command = join( + \ s:maparg[key] !=# '' + \ ? ['nnoremap', key, s:maparg[key]] + \ : ['nunmap', key] + \) + execute command + unlet s:maparg[key] + endfor endfunction |