*/
/*
- * PCHAR(lp, c) - put character 'c' at position 'lp'
+ * PBYTE(lp, c) - put byte 'c' at position 'lp'
*/
-#define PCHAR(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
+#define PBYTE(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
/*
* Position comparisons
#endif
#if defined(FEAT_VISUALEXTRA) || defined(PROTO)
+
+# ifdef FEAT_MBYTE
+/*
+ * Replace the character under the cursor with "c".
+ * This takes care of multi-byte characters.
+ */
+ static void
+replace_character(int c)
+{
+ int n = State;
+
+ State = REPLACE;
+ ins_char(c);
+ State = n;
+ /* Backup to the replaced character. */
+ dec_cursor();
+}
+
+# endif
/*
* Replace a whole area with one character.
*/
* with a multi-byte and the other way around. */
if (curwin->w_cursor.lnum == oap->end.lnum)
oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
- n = State;
- State = REPLACE;
- ins_char(c);
- State = n;
- /* Backup to the replaced character. */
- dec_cursor();
+ replace_character(c);
}
else
#endif
getvpos(&oap->end, end_vcol);
}
#endif
- PCHAR(curwin->w_cursor, c);
+ PBYTE(curwin->w_cursor, c);
}
}
#ifdef FEAT_VIRTUALEDIT
curwin->w_cursor.col -= (virtcols + 1);
for (; virtcols >= 0; virtcols--)
{
- PCHAR(curwin->w_cursor, c);
- if (inc(&curwin->w_cursor) == -1)
- break;
+#ifdef FEAT_MBYTE
+ if ((*mb_char2len)(c) > 1)
+ replace_character(c);
+ else
+ #endif
+ PBYTE(curwin->w_cursor, c);
+ if (inc(&curwin->w_cursor) == -1)
+ break;
}
}
#endif
}
else
#endif
- PCHAR(*pos, nc);
+ PBYTE(*pos, nc);
return TRUE;
}
return FALSE;
set virtualedit=
endfunc
+func Test_replace_end_of_line()
+ new
+ set virtualedit=all
+ call setline(1, range(20))
+ exe "normal! gg2jv10lr-"
+ call assert_equal(["1", "-----------", "3"], getline(2,4))
+ if has('multi_byte')
+ call setline(1, range(20))
+ exe "normal! gg2jv10lr\<c-k>hh"
+ call assert_equal(["1", "───────────", "3"], getline(2,4))
+ endif
+
+ bwipe!
+ set virtualedit=
+endfunc
+
func Test_edit_CTRL_G()
new
set virtualedit=insert