vi Alternative Required

Nicole Delbecque & Paul Bijnens FFAAC09 at cc1.kuleuven.ac.be
Wed Dec 19 04:40:09 AEST 1990


In article <25267 at adm.brl.mil>, rbottin at atl.calstate.edu (Richard John Botting)
says:
>
>I just caught up with this thread - I notice that nobody explained why the
>PC user has such a nasty experience when learning vi.  I have been teaching
>vi to PC and Mac users (mainly Comp Sci Majors) for 4 or 5 years and have
>come to the conclusion that I need a tape recording that says:
>
>        DON'T TOUCH THE ARROW KEYS!
>
>To say nothing of Insert, Delete, Home, End, PageUp, Page Down.
>
>Yes - 'vi'+'termcap' can interpret these keys when in command mode.
>But - on several systems that my students use the ANSI/vt100/at386/tab132
>what-have-you Escape sequence get fouled up - I assume that a buffer
>somewhere between the terminal and termcap overflows.

What you probably have, is an vi-implementation with a not-so-good
timeout-feature.  Some implementations do an alarm(1)-syscall to timeout
multi-character keys.  The 1-second resolution can in real-time be
anything from 1 second down to 0 (possibly on heavy loaded systems > 1).
There is a chance to have a premature timeout (0 seconds!).  Mostly
the terminal beeps, but if you press the left-arrow key (which sends
the codes ESC-[-D) and you get a premature timeout, vi beeps to tell
you '[' is not followed by a valid key (expecting another '[') and
the 'D' erases to the end of the line.  Some keys send sequences
beginning with ESC-O-whatever, resulting in an Open line above...

Is this what you are experiencing?  Then just do ":set notimeout".
This helped all those problems away at this site.
There is a "gotcha" however.  Just pressing <ESC> to stop insert mode
now temporarily leaves the cursor at the wrong place. Vi does not
yet know what the next key will be: cursor-movement (e.g. ESC-[-A)
or a command (e.g. ESC ESC-[-A or ESC 1G).
But I can live with that.

>In 'vi' (without special "map!" stuff) when the user sees a mistake on the
>previous line they tap ESC k j j ... or whatever. The PC user have
>developed a conditioned reflex so that there right hand is on the UP arrow
>before they remember to move their LEFT hand to the ESCape key...this is
>totally automatic. The ESC at the start of the Arrow key gets them
>out of insert mode, and (possibly) the following stuff deletes a line, or
>worse beeps and almost works...this helps to continue the reflex...

>[... stuff deleted ...]

>Has anyone got a set of 'map!' commands that implement arrow keys in
>'vi' Input mode?

Some map! stuff can help as you say.  Many people setup arrow keys
in insert mode.  I hate this.  You can setup the input maps for arrow
keys to first get out of insert mode and then do the movement, like:

  map! ^[[A ^[k
  map  ^[[A k
  etc...

This way, IMHO, I feel more consistent with command-mode <-> text-mode.

There has been a lot of stuff lately about those mappings and
the .exrc files.  Never seen how to set up a system wide .exrc file...
This is how we do it:

In /etc/profile  or /etc/cprofile  (on SysV.2)
or in /etc/rcopts/LOCPRF (on SysV.3)
or in .login or .profile if there is no system-wide startup-file...
(bourne-shell example:)

  if [ -r /usr/local/lib/ex/exrc.$TERM ]
  then EXINIT="so /usr/local/lib/ex/exrc.$TERM"
  else EXINIT="so /usr/local/lib/ex/exrc.dumb"
  fi
  if [ -r $HOME/.exrc ]
  then EXINIT="$EXINIT|so $HOME/.exrc"
  fi
  export EXINIT

The directory /usr/local/lib/ex contains mappings for most terminal
types in use (some terminals here even have NextPage-keys and other
rarely seen keys, why not use them...)
(Do not overload these files with mappings not used by most people
however!)
The directory also contains special purpose setups C-mode etc.
If necessary you can setup also $HOME/.exrc.$TERM this way.



More information about the Comp.unix.questions mailing list