On Sat, Feb 07, 2026 at 05:51:02PM -0600, Tim Chase wrote:
> On 2006-09-14 03:23, Bob Beck wrote:
> > When I'm a sysadmin and type vi, I want vi with all it's ususal
> > idiosyncracies so that it's basically the same no matter what system
> 
> Idiosyncracies aside, I'd still like to see it get bug fixes, such as
> this one that regularly bites me:
> 
>   $ yes hello | head -50 | fmt -100 > long_lines.txt
>   $ vi long_lines.txt
>   :g/^/.!fmt
> 
> results in
> 
>   +=+=+=+=+=+=+=+
>   Illegal address: only 6 lines in the file.
>   Error: unable to retrieve line 7; 4 lines added; 2 lines deleted
> 
> instead of re-fmt(1)ing each line individually.  Another case involves
> duplicating each line in the file:
> 
>   $ vi
>   :r !jot 100
>   :g/^/t.
> 
> which produces:
> 
>   +=+=+=+=+=+=+=+
>   Illegal address: only 150 lines in the file.
>   Error: unable to retrieve line 151; 50 lines added
> 
> This also ends up duplicating *every other* line, instead of duplicating
> *every* line.
> 
> -tkc
> 
> PS: FWIW, the problem exists in FreeBSD's vi/nvi too:
> 
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=270048
> 
> which I reported there at the same time I reported this on bugs@
> 
> https://marc.info/?l=openbsd-bugs&m=167830927129031&w=3
> 
> but never heard anything on either front.
> --
> 


Index: ex/ex_global.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/ex/ex_global.c,v
diff -u -p -u -p -r1.17 ex_global.c
--- ex/ex_global.c      27 May 2016 09:18:12 -0000      1.17
+++ ex/ex_global.c      8 Feb 2026 09:48:32 -0000
@@ -269,12 +269,12 @@ ex_g_insdel(SCR *sp, lnop_t op, recno_t 
                        /* If range less than the line, ignore it. */
                        if (rp->stop < lno)
                                continue;
-                       
+
                        /*
-                        * If range greater than the line, decrement or
-                        * increment the range.
+                        * If range greater than or equal to the line,
+                        * decrement or increment the range.
                         */
-                       if (rp->start > lno) {
+                       if (rp->start >= lno) {
                                if (op == LINE_DELETE) {
                                        --rp->start;
                                        --rp->stop;



-- 
Walter

Reply via email to