aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-22 22:37:23 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-22 22:37:23 +1200
commitb2d05a24bd541ca32ad77b41c07c13c25528dd6e (patch)
tree6884508e9da993296c267474e06877875df9aa9f
parentMerge branch 'release/v0.2.0' into develop (diff)
downloadvim-paste-insert-b2d05a24bd541ca32ad77b41c07c13c25528dd6e.tar.gz
vim-paste-insert-b2d05a24bd541ca32ad77b41c07c13c25528dd6e.zip
Support mapping cancel keys, add Esc as default
-rw-r--r--autoload/paste_insert.vim44
-rw-r--r--doc/paste_insert.txt5
2 files changed, 30 insertions, 19 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
diff --git a/doc/paste_insert.txt b/doc/paste_insert.txt
index 73036e4..ff17437 100644
--- a/doc/paste_insert.txt
+++ b/doc/paste_insert.txt
@@ -28,8 +28,9 @@ The `<Plug>(PasteInsert)` map in normal mode just does `:PasteInsert`.
OPTIONS *paste_insert-options*
*g:paste_insert_cancel*
-Set `g:paste_insert_cancel` to the key you want to cancel the pending paste in
-normal mode. This defaults to '<C-C>', for CTRL-C.
+Set `g:paste_insert_cancel` to a |List| of the keys you want to cancel the
+pending paste in normal mode. This defaults to `['<C-C>', '<Esc>']`, for
+CTRL-C and Escape.
AUTHOR *paste_insert-author*