@@ -2636,6 +2636,9 @@ do_addsub(
26362636 }
26372637 else
26382638 {
2639+ pos_T save_pos ;
2640+ int i ;
2641+
26392642 if (col > 0 && ptr [col - 1 ] == '-'
26402643 && (!has_mbyte ||
26412644 !(* mb_head_off )(ptr , ptr + col - 1 ))
@@ -2734,7 +2737,9 @@ do_addsub(
27342737 */
27352738 if (c == '-' )
27362739 -- length ;
2737- while (todel -- > 0 )
2740+
2741+ save_pos = curwin -> w_cursor ;
2742+ for (i = 0 ; i < todel ; ++ i )
27382743 {
27392744 if (c < 0x100 && isalpha (c ))
27402745 {
@@ -2743,10 +2748,10 @@ do_addsub(
27432748 else
27442749 hexupper = FALSE;
27452750 }
2746- // del_char() will mark line needing displaying
2747- (void )del_char (FALSE);
2751+ inc_cursor ();
27482752 c = gchar_cursor ();
27492753 }
2754+ curwin -> w_cursor = save_pos ;
27502755
27512756 /*
27522757 * Prepare the leading characters in buf1[].
@@ -2776,7 +2781,6 @@ do_addsub(
27762781 */
27772782 if (pre == 'b' || pre == 'B' )
27782783 {
2779- int i ;
27802784 int bit = 0 ;
27812785 int bits = sizeof (uvarnumber_T ) * 8 ;
27822786
@@ -2809,9 +2813,33 @@ do_addsub(
28092813 while (length -- > 0 )
28102814 * ptr ++ = '0' ;
28112815 * ptr = NUL ;
2816+
28122817 STRCAT (buf1 , buf2 );
2818+
2819+ // Insert just after the first character to be removed, so that any
2820+ // text properties will be adjusted. Then delete the old number
2821+ // afterwards.
2822+ save_pos = curwin -> w_cursor ;
2823+ if (todel > 0 )
2824+ inc_cursor ();
28132825 ins_str (buf1 ); // insert the new number
28142826 vim_free (buf1 );
2827+
2828+ // del_char() will also mark line needing displaying
2829+ if (todel > 0 )
2830+ {
2831+ int bytes_after = (int )STRLEN (ml_get_curline ())
2832+ - curwin -> w_cursor .col ;
2833+
2834+ // Delete the one character before the insert.
2835+ curwin -> w_cursor = save_pos ;
2836+ (void )del_char (FALSE);
2837+ curwin -> w_cursor .col = STRLEN (ml_get_curline ()) - bytes_after ;
2838+ -- todel ;
2839+ }
2840+ while (todel -- > 0 )
2841+ (void )del_char (FALSE);
2842+
28152843 endpos = curwin -> w_cursor ;
28162844 if (did_change && curwin -> w_cursor .col )
28172845 -- curwin -> w_cursor .col ;
0 commit comments