From 21eeff50594ac4c1f79ed96315367bd9d0728845 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 11 Jul 2019 16:40:59 +1200 Subject: End paste mode on TextChanged too --- autoload/paste_insert.vim | 18 ++++++++++++++++++ doc/paste_insert.txt | 12 ++++++------ 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', ['', '']) " 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* -- cgit v1.2.3