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 From d5019233597a241385364be4ffd704bbed3a731f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 11 Jul 2019 16:43:32 +1200 Subject: Improve comments --- autoload/paste_insert.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/paste_insert.vim b/autoload/paste_insert.vim index b5e36a0..5b26875 100644 --- a/autoload/paste_insert.vim +++ b/autoload/paste_insert.vim @@ -9,13 +9,12 @@ function! paste_insert#() abort autocmd User Start \ call s:Start() - " When starting insert mode, add completion hook for when we leave + " On insert mode start, add leaving hook to complete operation autocmd InsertEnter * \ 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 + " Text changed outside insert mode, complete operation if exists('##TextChanged') autocmd TextChanged * \ doautocmd paste_insert User Complete -- cgit v1.2.3 From fb05447751b5e9c3dc4119a784f382c68fdf29ec Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 11 Jul 2019 16:43:54 +1200 Subject: Bump VERSION --- VERSION | 2 +- doc/paste_insert.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 1d0ba9e..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +1.0.0 diff --git a/doc/paste_insert.txt b/doc/paste_insert.txt index 516f24c..35f1189 100644 --- a/doc/paste_insert.txt +++ b/doc/paste_insert.txt @@ -1,4 +1,4 @@ -*paste_insert.txt* For Vim version 7.0 Last change: 2019 Jun 23 +*paste_insert.txt* For Vim version 7.0 Last change: 2019 Jul 11 DESCRIPTION *paste_insert* -- cgit v1.2.3