xterm-color: Unknown terminal type

When I try to edit files using vi, I'm getting an error message:

$ vi foo.txt                                                                                                                                   
xterm-color: Unknown terminal type
I don't know what kind of terminal you are on - all I have is 'xterm-color'.
[Using open mode]

...and I can't edit my files normally. How can I fix this?

asked: 2012-02-06 by: automaciej


AirOnSkin answers:

Solaris knows a set of terminals by default. These terminal definitions reside at: /usr/share/lib/terminfo

To get a more extended selection of terminals, install the terminfo package.
The OpenCSW terminal definitions can be found at: /opt/csw/share/terminfo

Once you have decided on a terminal to use, you have to tell your shell where to find the definitions and what terminal to use. The corresponding system variables are TERMINFO & TERM

Now, to get a working OpenCSW xterm-color terminal export both variables with the right values:
export TERMINFO=/opt/csw/share/terminfo
export TERM=xterm-color

You may place the two lines above in your .bash_profile, or whatever file is appropriate for you shell, so you don't have to do this all the time manually.


automaciej commented:

You can set TERMINFO in /etc/default/login as well, this way it'll be a system-wide default, regardless of the shell.


laurent answers:

Three notes:

It will not work in /etc/default/login: this is not an /etc/profile equivalent, ie, it's not sourced as a script. Only selected variables there are used (cf login(1)).

As for TERMINFO: the initial shell is executed before the variable is set, so that shell will not find the proper information, and some of the issues will even seep into subshells which will have the right values from the start. Solaris 10's sshd does allow setting TERMINFO on connection, so to get it to work, a symlink must be created:

/usr/share/lib/terminfo/x/xterm-256color -> ../../../../../opt/csw/share/terminfo/x/xterm-256color

Use those commands:

  # cd /usr/share/lib/terminfo/x
  # ln -s ../../../../../opt/csw/share/terminfo/x/xterm-256color .

An alternative might be to replace Solaris 10's sshd by OpenSSH, allow setting TERMINFO in its sshd_config, and configuring the ssh client to send the value.

And lastly, a common issue is to have bad line return with colors in the prompt. It will make it difficult to know if the issue is a bad TERMINFO or a bad PS1. The first thing is to check carefully that color sequences are all properly escaped:

\[\e[xxx\]

Where xxx is the color code.

also, if the title of the window is set, it should be done in PROMPT_COMMAND, not PS1, eg:

PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'

Without that, bash will misinterpret the length of the prompt and put return at the wrong places.