@@ -2507,6 +2507,7 @@ op_insert(oparg_T *oap, long count1)
25072507{
25082508 long ins_len , pre_textlen = 0 ;
25092509 char_u * firstline , * ins_text ;
2510+ colnr_T ind_pre , ind_post ;
25102511 struct block_def bd ;
25112512 int i ;
25122513 pos_T t1 ;
@@ -2541,7 +2542,10 @@ op_insert(oparg_T *oap, long count1)
25412542#endif
25422543 /* Get the info about the block before entering the text */
25432544 block_prep (oap , & bd , oap -> start .lnum , TRUE);
2545+ /* Get indent information */
2546+ ind_pre = (colnr_T )getwhitecols_curline ();
25442547 firstline = ml_get (oap -> start .lnum ) + bd .textcol ;
2548+
25452549 if (oap -> op_type == OP_APPEND )
25462550 firstline += bd .textlen ;
25472551 pre_textlen = (long )STRLEN (firstline );
@@ -2593,6 +2597,14 @@ op_insert(oparg_T *oap, long count1)
25932597 && LT_POS (curbuf -> b_op_start_orig , t1 ))
25942598 oap -> start = curbuf -> b_op_start_orig ;
25952599
2600+ /* if indent kicked in, the firstline might have changed
2601+ * but only do that, if the indent actually increased */
2602+ ind_post = (colnr_T )getwhitecols_curline ();
2603+ if (curbuf -> b_op_start .col > ind_pre && ind_post > ind_pre )
2604+ {
2605+ bd .textcol += ind_post - ind_pre ;
2606+ bd .start_vcol += ind_post - ind_pre ;
2607+ }
25962608 /* If user has moved off this line, we don't know what to do, so do
25972609 * nothing.
25982610 * Also don't repeat the insert when Insert mode ended with CTRL-C. */
@@ -2754,7 +2766,7 @@ op_change(oparg_T *oap)
27542766# endif
27552767 firstline = ml_get (oap -> start .lnum );
27562768 pre_textlen = (long )STRLEN (firstline );
2757- pre_indent = (long )( skipwhite ( firstline ) - firstline );
2769+ pre_indent = (long )getwhitecols ( firstline );
27582770 bd .textcol = curwin -> w_cursor .col ;
27592771 }
27602772#endif
@@ -2779,7 +2791,7 @@ op_change(oparg_T *oap)
27792791 firstline = ml_get (oap -> start .lnum );
27802792 if (bd .textcol > (colnr_T )pre_indent )
27812793 {
2782- long new_indent = (long )( skipwhite ( firstline ) - firstline );
2794+ long new_indent = (long )getwhitecols ( firstline );
27832795
27842796 pre_textlen += new_indent - pre_indent ;
27852797 bd .textcol += new_indent - pre_indent ;
@@ -5065,8 +5077,7 @@ format_lines(
50655077#endif
50665078 if (second_indent > 0 ) /* the "leader" for FO_Q_SECOND */
50675079 {
5068- char_u * p = ml_get_curline ();
5069- int indent = (int )(skipwhite (p ) - p );
5080+ int indent = getwhitecols_curline ();
50705081
50715082 if (indent > 0 )
50725083 {
0 commit comments