SUMMARY (II): How to auto-setup DISPLAY, TERM, and key codes for vi, vim, and gvim.

From: O'Neal, Chris <onealwc_at_AGEDWARDS.com>
Date: Wed May 16 2001 - 11:42:33 EDT
UPDATE:
Unix System Adminer (USA) Bill "Elvis" Gibbs [elvis@goebusiness.com] found a
typo in my csh code, "default" was spelled wrong. Sorry, and thanks Elvis!

I display TERM and DISPLAY from .login so that when I first jump to another
box, I can see what was automatically setup for me. Sometimes it wrong, like
when I jump from server to server to server without returning home first
between jumps.  If this becomes a problem for me, I will request that me PC
get a static ip and put it out in a ~/.display.conf file on all servers and
read that in (Xterminals rule, PCs suck).  Also if your firm has a policy
that all global vars must come ssh you can use the value of SSH_CLIENT in
place of "who am i" and change the awk to suit.

SYNOPSIS:
Auto setting setenvs DISPLAY, TERM, and key codes can be done with some
limited successes.  Problems occur if you do not return to your original
terminal before jumping off to another server.  Auto-setting is done in
.login for csh or .profile for sh.

OS: 
Solaris 2.6, SunOS 4.1.4, MS-WinNT 

HARDWARE: 
Sparc, Intel

SOFTWARE:
Reflection-X, vi, vim, gvim.

ORIGINAL QUESTION: 
How do I setup my unix environment so that keyboard input is correct for vi
and command-line as I ssh, ftp or telnet from machine to machine? 

ORIGINAL PROBLEM:
As I move around from system to system, my key code setup for my keyboard
and environment vars DISPLAY and TERM are not self-setting like they once
were.  I get strange results from "vi" even after manual setting DISPLAY,
TERM, and "stty erase ^H".  Delete and arrow keys still do not work
correctly in vi.
 
ORIGINAL SUPPORTING DETAILS: 
This is probably a basic unix thing, but I have forgotten the answer.  The
company has moved all admins to a new work environment and I am encountering
some frustrations with keyboard entry not being correct.

Admins had been logging in via real NCD X-terminals to their main SunOS
4.1.4 servers and then ssh, ftp, or telnet their way around to different
boxes as needed.  With this, things worked great, environment vars such as
DISPLAY and TERM were always self-setting and correct (DISPLAY was always
"$xterminal:0.0" and TERM was either "xterm" or "vt125" depending on what
was needed) as you jumped from machine to machine, you never had to set
these or do any thing like "stty erase ^H" and everything worked.

Now all the X-terminals have been replaced with MS-WinNT PC using
Reflection-X software and a central Solaris 2.6 login-server has been
installed.  All logins goto this login-server and then from there you can
login (jump) to "your boxes" (SunOS 4.1.4 types).

As I jump from machine to machine, typically with ssh but sometimes with
telnet and ftp, I am having to manually set my DISPLAY, TERM and enter "stty
erase ^H" all over the place and still the interface between my keyboard and
vi (vim and gvim too) does not work correctly (delete key does not delete
and arrow keys work but move you to a line different from that displayed to
you).

I want to setup my personal environment so that I can return to the good old
days when the settings for DISPLAY, TERM, and key codes were always
correctly self-setting.  How do I do this? 

=================================================
SOLUTION:
I found a setting in my Reflection-X under Settings, Keyboard, Options,
UNCHECK Backspace key sends delete.

Sometimes I still get strange results in vi, vim, and gvim.  I have not
figured this out.  Also, the display no longer returns to previous view when
exiting vi like it did in SunOS 4.1.4, I guess that is a Solaris thing. 

I use csh and to have DISPLAY and TERM set I did the following in my .login
file.......

###
### Try to set DISPLAY to IP address.
###
setenv USER `/usr/ucb/whoami`
setenv RLOGIN `/bin/who am i | /bin/awk '{if (NF > 5 ) {print
(substr($6,2,length($6)-2))}}'`
if ( "${RLOGIN}" != "" ) then
        if ( `echo "${RLOGIN}" | grep :` == "" ) then
                setenv DISPLAY ${RLOGIN}:0.0
        else
                setenv DISPLAY ${RLOGIN}
        endif
endif

###
### Try to set TERM to correct setting.
###
setenv OSV `uname -r | awk -F. '{print $1}'`
switch ( $OSV )
        case 4:
                #SunOS
                setenv TERM xterm
                breaksw
        case 5:
                # Solaris
                setenv TERM dtterm
                breaksw
        default:
                # Unknown
                setenv TERM vt100
                breaksw
endsw

stty erase ^H rows 25
echo "DISPLAY= $DISPLAY"
echo "TERM= $TERM"

Add the following to the bottom of your .cshrc.....
###
### Set-up a mutli-line prompt with hostname, login, path, and history
number displayed.
###
set USER=`whoami`
set HOSTNAME=`uname -n`
alias setprompt 'set prompt="\\
${USER}@${HOSTNAME}:${cwd}\\
\! % "'
alias cd 'chdir \!* && setprompt'
setprompt           # to set the initial prompt

THANK YOU
I would like to thank the following for their responses...
- Moti Levy [mlevy@lannet.com]
- Peter [fbsdq@yahoo.com]
- Bryan Hodgson [bryan@verne.myxa.com]
- Marcelino Mata [mmata@multiinc.com]

Thx, 
Chris O'Neal 
email: onealwc@agedwards.com 
DATE: 05-15-2001 


****************************************************************************
***********
WARNING:  All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
****************************************************************************
***********
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers


***************************************************************************************
WARNING:  All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
***************************************************************************************
Received on Wed May 16 16:42:33 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:24:55 EDT