-/* $OpenBSD: vi.c,v 1.45 2017/05/28 07:27:01 anton Exp $ */
+/* $OpenBSD: vi.c,v 1.46 2017/05/31 06:59:12 anton Exp $ */
/*
* vi command editing
if (cmd[1] == 0)
vi_error();
else {
- int n;
-
- if (es->cursor + argcnt > es->linelen)
+ c1 = 0;
+ for (cur = es->cursor;
+ cur < es->linelen; cur++) {
+ if (!isu8cont(es->cbuf[cur]))
+ c1++;
+ if (c1 > argcnt)
+ break;
+ }
+ if (argcnt > c1)
return -1;
- for (n = 0; n < argcnt; ++n)
- es->cbuf[es->cursor + n] = cmd[1];
- es->cursor += n - 1;
+
+ del_range(es->cursor, cur);
+ while (argcnt-- > 0)
+ putbuf(&cmd[1], 1, 0);
+ while (es->cursor > 0)
+ if (!isu8cont(es->cbuf[--es->cursor]))
+ break;
+ es->cbuf[es->linelen] = '\0';
}
break;
# r: Replace character.
testseq "abcd\00332h2rxiy" " $ abcd\b\b\bxx\byxd\b\b\r\naxyxd"
+testseq "\0303\0266\0033ro" " $ \0303\0266\bo \b\b\r\no"
+testseq "\0342\0202\0254\0033ro" " $ \0342\0202\0254\bo \b\b\b\r\no"
+testseq "\0303\0266\00332ro" " $ \0303\0266\b\a\r\n\0303\0266"
# S: Substitute whole line.
testseq "oldst\0033Snew" " $ oldst\b\b\b\b\b \r $ new\r\nnew"