aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-07-11 16:40:59 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-07-11 16:40:59 +1200
commit21eeff50594ac4c1f79ed96315367bd9d0728845 (patch)
treecbec6a03d26625008bbc6da58e6f872c01be6ed2
parent6fb235169f53b59e589562ebbdc6eeea573c97b0 (diff)
downloadvim-paste-insert-21eeff50594ac4c1f79ed96315367bd9d0728845.tar.gz
vim-paste-insert-21eeff50594ac4c1f79ed96315367bd9d0728845.zip
End paste mode on TextChanged too
-rw-r--r--autoload/paste_insert.vim18
-rw-r--r--doc/paste_insert.txt12
2 files changed, 24 insertions, 6 deletions
diff --git a/autoload/paste_insert.vim b/autoload/paste_insert.vim
index 946e09a..b5e36a0 100644
--- a/autoload/paste_insert.vim
+++ b/autoload/paste_insert.vim
@@ -14,6 +14,18 @@ function! paste_insert#() abort
\ autocmd paste_insert InsertLeave *
\ doautocmd paste_insert User Complete
+ " User changed the text somehow, presumably a paste, so complete the
+ " operation; use the new TextChanged event if we've got it
+ if exists('##TextChanged')
+ autocmd TextChanged *
+ \ doautocmd paste_insert User Complete
+ else
+ autocmd CursorMoved *
+ \ if changenr() > b:paste_insert_changenr
+ \| doautocmd paste_insert User Complete
+ \|endif
+ endif
+
" User waits too long in normal mode, timeout
autocmd CursorHold *
\ doautocmd paste_insert User Timeout
@@ -38,6 +50,9 @@ let s:cancel_keys = get(g:, 'paste_insert_cancel_keys', ['<C-C>', '<Esc>'])
" Start the paste: remap any cancel keys, set 'paste'
function! s:Start() abort
+ if exists('##TextChanged')
+ let b:paste_insert_changenr = changenr()
+ endif
for key in s:cancel_keys
if maparg(key, 'n') ==# ''
execute join(['nnoremap', key,
@@ -51,6 +66,9 @@ endfunction
" Stop the paste: unset 'paste', restore prior function of cancel key
function! s:Stop() abort
+ if exists('##TextChanged')
+ unlet b:paste_insert_changenr
+ endif
set nopaste paste?
for key in s:cancel_keys
execute join(['nunmap', key])
diff --git a/doc/paste_insert.txt b/doc/paste_insert.txt
index 68f1ef9..516f24c 100644
--- a/doc/paste_insert.txt
+++ b/doc/paste_insert.txt
@@ -3,13 +3,13 @@
DESCRIPTION *paste_insert*
This plugin implements a method for setting paste mode with the 'paste' option
-for only the duration of the next insert operation, to avoid the hassle of
-forgetting to unset the option after inserting.
+for only the duration of the next insert operation or normal mode change, to
+avoid the hassle of forgetting to unset the option after inserting.
-It includes a timeout if insert mode isn't entered within 'updatetime'
-seconds, or if the user navigates away from the buffer or window. It can also
-be cancelled in normal mode with CTRL-C or Escape. These keys can be changed
-if they are already mapped or otherwise unsuitable.
+It includes a timeout if the text isn't changed and insert mode isn't entered
+within 'updatetime' seconds, or if the user navigates away from the buffer or
+window. It can also be cancelled in normal mode with CTRL-C or Escape. These
+keys can be changed if they are already mapped or otherwise unsuitable.
REQUIREMENTS *paste_insert-requirements*