patch 9.2.0473: Pasting ". register without autocommands breaks TextPut*
Commit:
https://github.com/vim/vim/commit/a70b7a85afad9dc8eeae2a97142dc744cf3205e6
Author: zeertzjq <
zeer...@outlook.com>
Date: Mon May 11 16:49:19 2026 +0000
patch 9.2.0473: Pasting ". register without autocommands breaks TextPut*
Problem: Pasting ". register without TextPut* autocommands breaks
subsequent TextPut* autocommands (after 9.2.0470).
Solution: Only decrement add_last_insert if it has been incremented
(zeertzjq).
closes: #20192
Signed-off-by: zeertzjq <
zeer...@outlook.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/register.c b/src/register.c
index 44e6aba6f..86ac02cfc 100644
--- a/src/register.c
+++ b/src/register.c
@@ -1736,7 +1736,8 @@ do_put(
stuffcharReadbuff(VIsual_mode);
#ifdef FEAT_EVAL
- if (has_textputpre() || has_textputpost())
+ bool has_textput_events = has_textputpre() || has_textputpost();
+ if (has_textput_events)
add_last_insert++;
#endif
@@ -1748,11 +1749,10 @@ do_put(
// TextPutPost after TextPutPre.
if (has_textputpre())
put_do_autocmd('.', NULL, NULL, false, dir);
-
if (has_textputpost())
put_do_autocmd('.', NULL, NULL, true, dir);
- if (--add_last_insert == 0)
+ if (has_textput_events && --add_last_insert == 0)
ga_clear(&last_insert_ga);
#endif
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 2a3616893..ecd5791c9 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -6069,22 +6069,27 @@ func Test_TextPutX()
au! TextPutPre
let g:pre_event = []
- " Test that recursive ". register calls have the same contents for post and
- " pre
- au TextPutPre * put . | let g:pre_event = copy(v:event)
- au TextPutPost * let g:post_event = copy(v:event)
+ for round in range(2)
+ " Recursive ". register calls have the same contents for post and pre.
+ au TextPutPre * put . | let g:pre_event = copy(v:event)
+ au TextPutPost * let g:post_event = copy(v:event)
- call feedkeys("iinserted\<Esc>", 'x')
- norm! ".p
+ call feedkeys("iinserted\<Esc>", 'x')
+ norm! ".p
- call assert_equal(
- \ #{regcontents: ["inserted"], regname: '.',
- \ operator: 'p', regtype: 'v', visual: v:false},
- \ g:pre_event)
- call assert_equal(g:pre_event, g:post_event)
+ call assert_equal(
+ \ #{regcontents: ["inserted"], regname: '.',
+ \ operator: 'p', regtype: 'v', visual: v:false},
+ \ g:pre_event)
+ call assert_equal(g:pre_event, g:post_event)
- au! TextPutPre
- au! TextPutPost
+ au! TextPutPre
+ au! TextPutPost
+
+ " Pasting ". register without TextPutPre/TextPutPost autocommands should
+ " not interfere with these autocommands in the next round.
+ norm! ".p
+ endfor
unlet g:post_event
unlet g:pre_event
diff --git a/src/version.c b/src/version.c
index 3aff29a29..f96e170e4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 473,
/**/
472,
/**/