@@ -2544,6 +2544,7 @@ op_insert(oap, count1)
25442544 char_u * firstline , * ins_text ;
25452545 struct block_def bd ;
25462546 int i ;
2547+ pos_T t1 ;
25472548
25482549 /* edit() changes this - record it for OP_APPEND */
25492550 bd .is_MAX = (curwin -> w_curswant == MAXCOL );
@@ -2617,8 +2618,16 @@ op_insert(oap, count1)
26172618 }
26182619 }
26192620
2621+ t1 = oap -> start ;
26202622 edit (NUL , FALSE, (linenr_T )count1 );
26212623
2624+ /* When a tab was inserted, and the characters in front of the tab
2625+ * have been converted to a tab as well, the column of the cursor
2626+ * might have actually been reduced, so need to adjust here. */
2627+ if (t1 .lnum == curbuf -> b_op_start_orig .lnum
2628+ && lt (curbuf -> b_op_start_orig , t1 ))
2629+ oap -> start = curbuf -> b_op_start_orig ;
2630+
26222631 /* If user has moved off this line, we don't know what to do, so do
26232632 * nothing.
26242633 * Also don't repeat the insert when Insert mode ended with CTRL-C. */
@@ -2644,10 +2653,11 @@ op_insert(oap, count1)
26442653#endif
26452654 )
26462655 {
2656+ int t = getviscol2 (curbuf -> b_op_start_orig .col ,
2657+ curbuf -> b_op_start_orig .coladd );
26472658 oap -> start .col = curbuf -> b_op_start_orig .col ;
2648- pre_textlen -= getviscol2 (oap -> start .col , oap -> start .coladd )
2649- - oap -> start_vcol ;
2650- oap -> start_vcol = getviscol2 (oap -> start .col , oap -> start .coladd );
2659+ pre_textlen -= t - oap -> start_vcol ;
2660+ oap -> start_vcol = t ;
26512661 }
26522662 else if (oap -> op_type == OP_APPEND
26532663 && oap -> end .col
@@ -2660,12 +2670,13 @@ op_insert(oap, count1)
26602670#endif
26612671 )
26622672 {
2673+ int t = getviscol2 (curbuf -> b_op_start_orig .col ,
2674+ curbuf -> b_op_start_orig .coladd );
26632675 oap -> start .col = curbuf -> b_op_start_orig .col ;
26642676 /* reset pre_textlen to the value of OP_INSERT */
26652677 pre_textlen += bd .textlen ;
2666- pre_textlen -= getviscol2 (oap -> start .col , oap -> start .coladd )
2667- - oap -> start_vcol ;
2668- oap -> start_vcol = getviscol2 (oap -> start .col , oap -> start .coladd );
2678+ pre_textlen -= t - oap -> start_vcol ;
2679+ oap -> start_vcol = t ;
26692680 oap -> op_type = OP_INSERT ;
26702681 }
26712682 }
0 commit comments