Differencebetween Xterm-Color & Xterm-256Color

What is the difference between xterm-color & xterm-256color?

xterm-256color describes Xterm with support for 256 colors enabled. xterm-color describes an older branch of Xterm that supports eight colors. xterm-color is not recommended, since it describes a variant of Xterm that’s less functional and that you’re not likely to be using. Usually you’ll want to use xterm, xterm-16color or xterm-256color.

In particular, xterm-256color is the default for Terminal starting with Mac OS X 10.7 Lion, with the next-best recommended values being xterm-16color or xterm (which only describes support for eight ANSI colors). Prior to 10.7, xterm-color was the default because Terminal didn’t support some critical features described by the recommended Xterm terminfo values, e.g., Background Color Erase (BCE), modern codes for switching main/alternate screens, 256 colors.

Sometimes people explicitly set TERM to xterm-color (as opposed to the recommended Xterm values) to disable functionality or work around incompatibilities between the available terminfo values on a particular computer and the terminal emulator being used.

Note that technically Terminal should have its own up-to-date terminfo values that describe exactly which features it supports, instead of using the values for Xterm, but:

  1. There isn’t one that’s up to date currently. nsterm represents Terminal’s ancestor from NeXTSTEP. Someone apparently has updated nsterm recently (sometime in the past couple of years), but I don’t know whether that has made its way into the ncurses distribution, and it may not be completely up to date with Terminal in 10.7.
  2. A number of programs and shell customization scripts explicitly check whether $TERM starts with (or is equal to) xterm. So some users would still need to know about using the recommended Xterm values with Terminal for compatibility with those.

If you’re not familiar with the terminfo system, take a look at the x-man-page://5/terminfo man page. Also, you can use the infocmp command to view the current terminfo settings or compare two different ones, e.g., infocmp xterm-color xterm-256color will show you all the differences between those two.

Vim: Difference between t_Co=256 and term=xterm-256color in conjunction with TMUX

When you don't use tmux or screen, you only need to configure your terminal emulators to advertise themselves as "capable of displaying 256 colors" by setting their TERM to xterm-256color or any comparable value that works with your terminals and platforms. How you do it will depend on the terminal emulator and is outside of the scope of your question and this answer.

You don't need to do anything in Vim as it's perfectly capable to do the right thing by itself.

When you use tmux or screen, those programs set their own default value for $TERM, usually screen, and Vim does what it has to do with the info it is given.

If you want a more uniform (and colorful) behavior, you must configure them to use a "better" value for $TERM:

  • tmux

    Add this line to ~/.tmux.conf:

    set -g default-terminal "screen-256color"
  • screen

    Add this line to ~/.screenrc:

    term "screen-256color"

Now, both multiplexers will tell Vim they support 256 colors and Vim will do what you expect it to do.

edit

My answer assumes that you are able to edit those configuration files but, since you are able to edit your ~/.vimrc, I don't think that I'm that far off the mark.

edit 2

The value of the term option (retrieved with &term) is the name of the terminal as picked up by Vim upon startup. That name is what you are supposed to setup in your terminal emulator itself.

The value of the t_Co option (&t_Co) is what Vim considers to be the maximum number of colors that can be displayed by the host terminal. It is defined according to the entry corresponding to $TERM in terminfo:

 term            | t_Co
-----------------+------
xterm | 8
xterm-256color | 256
screen | 8
screen-256color | 256

When Vim starts up, it gets the value of the TERM environment variable, queries the terminfo database with that value and stores a number of informations on its environment in several t_… variables among which… the number of colors available in t_Co. Given a "legal" terminal type (one that Vim can lookup), Vim always assumes the correct number of colors.

Setting t_Co to 256 while leaving term to its Vim-defined value — or, more generally, setting t_Co and/or term to values that don't match with the host terminal — makes no sense and will likely create troubles when Vim sends a signal that is not understood by the terminal or vice-versa.

While it is entirely possible to do so, messing with t_Co and term in Vim is both totally useless and possibly harmful.

Again, just setup your terminal emulators and terminal multiplexers correctly. That's really all you need.

If you end up in a terminal multiplexer or a terminal emulator where you can't define a correct TERM, then and only then you can force Vim to assume 256 colors. To that end, changing the value of t_Co is the only thing that makes sense:

if &term == "screen"
set t_Co=256
endif

So… if you can configure each individual part:

  • terminal emulator: xterm-256color
  • tmux/screen: screen-256color
  • vim: nothing

and you are done.

If you can't control every part, use a simple conditional in your ~/.vimrc to set t_Co according to &term but don't change the value of term.

But if you can edit a ~/.vimrc there's no reason you can't edit a ~/.screenrc or ~/.tmux.conf or ~/.bashrc or whatever.

nano error: Error opening terminal: xterm-256color

On Red Hat this worked for me:

export TERM=xterm

further info here: http://www.cloudfarm.it/fix-error-opening-terminal-xterm-256color-unknown-terminal-type/

Error opening terminal: xterm-256color

Probably due to a Lion upgrade/install. Did you do that recently @Gih?

Possible duplicate (with fix) at
nano error: Error opening terminal: xterm-256color

EDIT:

Easiest fix (takes 10 seconds)...from Michael:

There is a solution much easier:
http://ricochen.wordpress.com/2011/07/23/mac-os-x-lion-terminal-color-remote-access-problem-fix/



Related Topics



Leave a reply



Submit