From: Walter Alejandro Iglesias Subject: Re: Another vi(1) paste improvement (Rationale) To: tech@openbsd.org Cc: "Todd C. Miller" Date: Mon, 1 Sep 2025 12:29:37 +0200 I received a private message from someone arguing that he needs vi(1) to be compatible, bug for bug, with all versions of nvi on all operating systems. So, I will anticipate other objections of this type that may arise. A bit of history. The following comment (common/put.c, line 146) is illustrative: /* * !!! * In the historical 4BSD version of vi, character mode puts within * a single line have two cursor behaviors: if the put is from the * unnamed buffer, the cursor moves to the character inserted which * appears last in the file. If the put is from a named buffer, * the cursor moves to the character inserted which appears first * in the file. So far, I could reproduce this behavior only in this version of vi: https://ex-vi.sourceforge.net In System III/V, it was changed at some point and * the cursor always moves to the first character. In both versions * of vi, character mode puts that cross line boundaries leave the * cursor on the first character. Nvi implements the System III/V As far as I've investigated, the only related application that, as nvi, chose the second behavior explained in the comment is FreeBSD's sh vi-mode. The rest I've tested so far (vim, bash, ksh) solved this in a third way, which is to *always* move the cursor to the *last* character. * behavior, and expect POSIX.2 to do so as well. */ See: https://pubs.opengroup.org/onlinepubs/9799919799 In the left panel browse to: Base Definitions / System Interfaces / Shell & Utilities / vi POSIX.2, under the title "Put from Buffer Following" and "Put from Buffer Before" still says: If the buffer text is in character mode: [...] 2. Otherwise, if the buffer is the unnamed buffer, set to the last column on which any portion of the last character from the buffer is displayed. Currently nvi is not POSIX compliant. My reasoning ------------ Currently the output of hitting 'p' consecutive times is useless (except, of course, with single characters or single lines, where is obviously irrelevant.) This means that arguments related to muscle memory, backward compatibility or compatibility with other versions have little or no weight in this particular case. Speaking of simply pasting text once. I make *intensive* use of vi and nvi2 on daily bases (editing books), cutting and pasting text hours and hours. As I see it, from the usage point of view, where is more convenient the cursor land when pasting (char or line mode) depends on the context. Surely, like me, vi(1) users have alternately used vim, bash, ksh, etc. and haven't had any trouble adapting from one behavior to the other (I bet most hadn't noticed the difference.) The *character* mode pasting I'm proposing now, doesn't go against the historical evolution or the current behavior of any vi editing mode present in well known applications. So the only thing we could call *innovation* in my proposal comes with line mode pasting with 'p'. If anyone finds any cases where the new behavior (moving the cursor to the last line) might be less convenient than the current one, please describe it to me with an example. (I've already showed one advantage of my proposal against the current behavior.) Finally, in case some day this POSIX definition is updated, in my opinion, the sensible thing would be to change it to support a reasonable, useful behavior. -- Walter