Download raw body.
ksh vi mode: stop 'P' command from moving the cursor
Hi Ingo,
On Mon, Apr 21, 2025 at 11:38:01PM +0200, Ingo Schwarze wrote:
> Hello,
>
> here is a patch to change the behaviour of the "paste before" (P) command
> in the VI command line editing mode of ksh(1).
>
> The current behaviour is very weird. When you insert just once (1P),
[...]
Contary to vim or traditional vi (https://ex-vi.sourceforge.net/), our
version of vi(1) (as well as nvi2 from ports) doesn't move the cursor
when pasting from the buffer. You could imitate this behavior by adding
one more modification to your diff:
Index: vi.c
===================================================================
RCS file: /cvs/src/bin/ksh/vi.c,v
diff -u -p -r1.61 vi.c
--- vi.c 21 Apr 2025 20:06:15 -0000 1.61
+++ vi.c 22 Apr 2025 07:47:56 -0000
@@ -695,7 +695,6 @@ vi_cmd(int argcnt, const char *cmd)
{
int ncursor;
int cur, c1, c2, c3 = 0;
- int any;
struct edstate *t;
if (argcnt == 0 && !is_zerocount(*cmd))
@@ -848,11 +847,8 @@ vi_cmd(int argcnt, const char *cmd)
case 'P':
modified = 1; hnum = hlast;
- any = 0;
while (putbuf(ybuf, yanklen, 0) == 0 && --argcnt > 0)
- any = 1;
- if (any && es->cursor != 0)
- es->cursor--;
+ continue;
if (argcnt != 0)
return -1;
break;
@@ -1486,7 +1482,6 @@ putbuf(const char *buf, int len, int rep
es->linelen += len;
}
memmove(&es->cbuf[es->cursor], buf, len);
- es->cursor += len;
return 0;
}
--
Walter
ksh vi mode: stop 'P' command from moving the cursor