The TERM
environment variable is used by your terminal emulator to indicate which type of control string it supports. For the most part you should not override this variable, but there is a narrow set of circumstances where the default value can be incorrect or at least not optimal.
For example in most distributions the default value for a console terminal is linux
and for a graphical terminal xterm
. That’s fine, but don’t allow you to enjoy vim
or screen
256 color mode in graphical mode.
A traditional xterm
only supports 16 colors and this value is specify into the terminfo
database.
As you can image, changing the xterm
entry would have made users of the newer versions happy but also broken the configuration for others. Instead a new value xterm-256color
was declared. That may seems fine but when you log in remotely to machines with an older terminal database, the value isn’t recognized.
In this case the only viable solution left is to override the TERM
value in order to unset the 256 color mode. You can do it by adding something like that to the .bash_profile
on the remote machine:
if echo $TERM | grep -q -- '-256color'; then
export TERM=`echo -n $TERM | sed 's/-256color//'`
fi