Download raw body.
ksh vi mode: stop 'P' command from moving the cursor
Hello Nils Ola,
NilsOla Nilsson wrote on Thu, Apr 24, 2025 at 06:32:49PM +0200:
> On Thu, Apr 24, 2025 at 05:39:56PM +0200, Ingo Schwarze wrote:
>> we have now three options what to do with 'P' in ksh(1) VI mode; one
>> of them also changes the behaviour of 'p'. So i'm asking people:
>> which one of the three do you prefer?
>>
>> If people prefer one of the two solutions proposed by Walter, i'll
>> polish, test, and commit that. Otherwise, i'll commit the diff i
>> posted earlier. Something needs to be committed because right now,
>> the 'P' command misbehaves with UTF-8.
>> Walter Alejandro Iglesias wrote on Thu, Apr 24, 2025 at 10:49:02AM +0200:
>>> On Mon, Apr 21, 2025 at 11:38:01PM +0200, Ingo Schwarze wrote:
>>>> here is a patch to change the behaviour of the "paste before" (P) command
>>>> in the VI command line editing mode of ksh(1).
>>> With your diff, after pasting with the 'P' command the cursor lands one
>>> character *after* the last character in the string pasted.
>> Correct.
>> That is also the character the cursor is on before pasting.
>>> I'm not saying this is wrong, maybe it's more convenient, but it's not
>>> what the 'p' command does
>> Correct.
>> In our ksh(1), 'p' puts the cursor on the last character inserted.
> One aspect of this is what happens if you paste several
> times without moving the cursur in between.
> Tested like this:
> - started with "======="
> - have "abcde" in the paste buffer
> - position the cursor somewhere in the "======="-string
> - paste five times
> The result is
> for nvi(in ports) and vi pasting with p (messing it up)
> ====aaaaabcdebcdebcdebcdebcde===
> for nvi(in ports) and vi pasting with P (as expected)
> ====abcdeabcdeabcdeabcdeabcde===
> for vim, nvim and bash pasting with p (as expected)
> ====abcdeabcdeabcdeabcdeabcde===
> for vim, nvim and bash pasting with P (messing it up)
> ====abcdabcdabcdabcdabcdeeeee===
> for ksh, kakuone and helix pasting with either p or P (as expected)
> ====abcdeabcdeabcdeabcdeabcde===
>
> No strong opinion about anything, but this could be
> seen as a flaw (or two different flaws) in vi and vim,
> that can not be corrected any more, but is fixed in
> ksh, kakuone and helix.
Interesting, thank you for your feedback.
That sounds like a relevant argument in favour of my original patch.
Patrick Keshishian also presented reasonable arguments in favour of
that least intrusive change, namely that he would expect "paste before"
to leave the cursor on the character where it was.
So, i'm looking for an OK for this unchanged patch:
Ingo
Index: regress/bin/ksh/edit/vi.sh
===================================================================
RCS file: /cvs/src/regress/bin/ksh/edit/vi.sh,v
diff -u -r1.10 vi.sh
--- regress/bin/ksh/edit/vi.sh 21 Apr 2025 20:06:15 -0000 1.10
+++ regress/bin/ksh/edit/vi.sh 24 Apr 2025 18:10:31 -0000
@@ -118,7 +118,13 @@
# P: Paste at current position.
testseq "abcde\0033hDhP" " # abcde\b\b \b\b\b\bdebc\b\b"
-testseq "abcde\0033hDh2P" " # abcde\b\b \b\b\b\bdedebc\b\b\b"
+testseq "abcde\0033hDh2P" " # abcde\b\b \b\b\b\bdedebc\b\b"
+testseq "A\0033xa\0303\0200\00332Px" \
+ " # A\b \b\0303\0200\bAA\0303\0200\b \b\b\b"
+testseq "\0302\0251\0033xaA\0033Px" \
+ " # \0302\0251\b \b\bA\b\0302\0251A\b \b\b"
+testseq "\0302\0251\0033xa\0303\0200\0033Px" \
+ " # \0302\0251\b \b\b\0303\0200\b\0302\0251\0303\0200\b \b\b\b"
# p: Paste after current position.
testseq "abcd\0033hDhp" " # abcd\b\b \b\b\b\bacdb\b\b"
Index: bin/ksh/vi.c
===================================================================
RCS file: /cvs/src/bin/ksh/vi.c,v
diff -u -r1.61 vi.c
--- bin/ksh/vi.c 21 Apr 2025 20:06:15 -0000 1.61
+++ bin/ksh/vi.c 24 Apr 2025 18:10:31 -0000
@@ -695,7 +695,6 @@
{
int ncursor;
int cur, c1, c2, c3 = 0;
- int any;
struct edstate *t;
if (argcnt == 0 && !is_zerocount(*cmd))
@@ -848,11 +847,8 @@
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;
ksh vi mode: stop 'P' command from moving the cursor