[comp.unix.wizards] vi bug?

stanonik@nprdc.arpa (Ron Stanonik) (11/19/86)

One of our users pointed out a problem with vi (we're running
4.2bsd on a vax 780, but the problem seems to also occur on
suns running release 3 and ats running ibm xenix 2.0).  His
note is pretty clear.  Any fixes/ideas?
Thanks,
Ron Stanonik
stanonik@nprdc.arpa

From: trejo (Len Trejo)
Date: 18 November 1986 0844-PST (Tuesday)
To: stanonik
Subject: A problem with vi

This is a file that will serve to demonstrate a problem I'm having
with the vi editor.  The problem is a failure of vi to properly "put"
a large (half a line or so) chunk of text into another line when
two conditions exist: 1) The wrapmargin is set to some non-zero value
(i.e. 5 or 10); 2) The put is done near the end of the line (i.e., the
inserted text will cross the wrapmargin).  Here is a prescription to
demonstrate the problem.  Down below is some text to be yanked and
then put elsewhere.  First, set the wrapmargin from command mode by
typing ':se wm=10'.  Then yank the text below and put it at the target
location on this line, which is marked with a capital t:  .........T
You can do this by moving the cursor to the text below and typing 'y$'
from command mode then moving the cursor to the target location (T)
and typing 'P' from command mode.  When I do this the "put" loses many
characters and then opens a new line below the target line and puts
some text there.  It's really very messy because it can't be
completely undone with the 'undo' command.  Please let me know if this
occurs for you also.

Len

lambert@mcvax.uucp (Lambert Meertens) (11/21/86)

In article <939@brl-adm.ARPA> stanonik@nprdc.arpa (Ron Stanonik) writes:
> One of our users pointed out a problem with vi [..]:
> The problem is a failure of vi to properly "put" a large (half a line
> or so) chunk of text into another line when two conditions exist: 1) The
> wrapmargin is set to some non-zero value; 2) The put is done near the end
> of the line (i.e., the inserted text will cross the wrapmargin).

A third condition is that the text in the put buffer contains spaces.  What
seems to happen is that a space on which wrap should occur AND the character
following it are not inserted.  Instead, the non-space characters following
each such space are interpreted as commands(!), in the reverse order of that
in which they occur.

This annoying bug has been in vi as long as I can remember and has persisted
up through BSD 4.3.  It has been signalled before on the net.  It is
probably just a silly coding error that should be easy to spot (assuming
you know your way around in the vi code), what with such specific and
repeatable behaviour.

-- 

Lambert Meertens, CWI, Amsterdam; lambert@mcvax.UUCP

madden@net1.UCSD.EDU (Jim Madden) (11/29/86)

Here's a patch to the 3.7 version of vi that prevents the peculiar
situation in which text which wraps around the end of a line
during a "put" is interpreted as commands:

*** /tmp/,RCSt1017647	Fri Nov 28 21:49:00 1986
--- ex_vops2.c	Wed Dec 18 12:47:03 1985
***************
*** 1,5
  /* Copyright (c) 1981 Regents of the University of California */
  static char *sccsid = "@(#)ex_vops2.c	6.5 7/26/81";
  #include "ex.h"
  #include "ex_tty.h"
  #include "ex_vis.h"

--- 1,8 -----
  /* Copyright (c) 1981 Regents of the University of California */
  static char *sccsid = "@(#)ex_vops2.c	6.5 7/26/81";
+ 
+ /* $Header: ex_vops2.c,v 1.2 83/11/01 14:34:01 muller Exp $ */
+ 
  #include "ex.h"
  #include "ex_tty.h"
  #include "ex_vis.h"
***************
*** 4,9
  #include "ex_tty.h"
  #include "ex_vis.h"
  
  /*
   * Low level routines for operations sequences,
   * and mostly, insert mode (and a subroutine

--- 7,19 -----
  #include "ex_tty.h"
  #include "ex_vis.h"
  
+ /* $Log:	ex_vops2.c,v $
+  * Revision 1.2  83/11/01  14:34:01  muller
+  * Kludge patch to let puts that generate long lines operate on terminals
+  * with wrapmargin set and screen insert mode (h19s). Such puts will cause
+  * random text changes without the patch.
+  *  */
+ 
  /*
   * Low level routines for operations sequences,
   * and mostly, insert mode (and a subroutine
***************
*** 621,627
  				gobbled = 1;
  				continue;
  			}
! 			if (value(WRAPMARGIN) &&
  				(outcol >= OCOLUMNS - value(WRAPMARGIN) ||
  				 backsl && outcol==0) &&
  				commch != 'r') {

--- 631,642 -----
  				gobbled = 1;
  				continue;
  			}
! 			if (value(WRAPMARGIN) && !vglobp &&
! 				/*
! 				 * vglopb implies this is not really a keyboard
! 				 * text insert.  This test avoids trying to
! 				 * split lines at the wrapmargin for puts.
! 				 */
  				(outcol >= OCOLUMNS - value(WRAPMARGIN) ||
  				 backsl && outcol==0) &&
  				commch != 'r') {