256 colour terminals

Using 256 colours in terminals is well-supported in Linux distributions these days, and also in Windows terminal emulators like PuTTY. Using 256 colours is great for Vim colorschemes in particular, but also very useful for Tmux colouring or any other terminal application where a slightly wider colour space might be valuable. Be warned that once you get this going reliably, there’s no going back if you spend a lot of time in the terminal.


To set this up for xterm or emulators that use xterm as the default value for $TERM, such as xfce4-terminal or gnome-terminal, it generally suffices to check the options for your terminal emulator to ensure that it will allow 256 colors, and then use the TERM string xterm-256color for it.

An earlier version of this post suggested changing the TERM definition in .bashrc, which is generally not a good idea, even if bounded with conditionals as my example was. You should always set the terminal string in the emulator itself if possible, if you do it at all.

Be aware that older systems may not have terminfo definitions for this terminal, but you can always copy them in using a private .terminfo directory if need be.


To use 256 colours in Tmux, you should set the default terminal in .tmux.conf to be screen-256color:

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

This will allow you to use color definitions like colour231 in your status lines and other configurations. Again, this particular terminfo definition may not be present on older systems, so you should copy it into ~/.terminfo/s/screen-256color on those systems if you want to use it everywhere.

GNU Screen

Similarly, to use 256 colours in GNU Screen, add the following to your .screenrc:

term screen-256color


With the applicable options from the above set, you should not need to change anything in Vim to be able to use 256-color colorschemes. If you’re wanting to write or update your own 256-colour compatible scheme, it should either begin with set t_Co=256, or more elegantly, check the value of the corresponding option value is &t_Co is 256 before trying to use any of the extra colour set.

The Vim Tips Wiki contains a detailed reference of the colour codes for schemes in 256-color terminals.

7 thoughts on “256 colour terminals

  1. Pingback: Use 256 colors in your terminal « 0ddn1x: tricks with *nix

  2. In Perl, we can access them with Term::ExtendedColor

    perl -MTerm::ANSIColor -E 'say colored "just one blue?", "blue"'
    perl -MTerm::ExtendedColor=fg -E 'say fg "blue$_", "lots of blues!" for 1..17'
  3. On my Debian box, the TERM setting is xterm+256color (not xterm-256color), but it causes problems with the automatic color detection in git:

    $ git diff
    WARNING: terminal is not fully functional
  4. Just wanted to say that this post along with your TERM strings post helped me end my frustration with getting urvxt, screen and vim to play nice on my Debian box. Thanks!

  5. Pingback: BASH history articles - Best Bash History Settings (at top) | kossboss

  6. Pingback: Unix/Linux:How can I print text using any one of the 256 colors that the terminal allows? – Unix Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use Markdown if you want.