On *nix systems, the very purpose of setting the $TERM environment variable to a terminfo entry that describes your terminal's capabilities, including the number of supported colors is to advertise these capabilities to the applications that will run inside your terminal.
In other words, the reason you set this variable in the first place is to tell Vim (or mutt.. slrn.. ELinks.. etc.) .. Hey.. among other things.. I support 256 colors, did you know..?
As a result, there is no point whatsoever in adding bloat to your vimrc to test the value of $TERM in order to set the value of the t_Co Vim variable. Vim is smart enough to pick up the supported number of colors from the terminfo entry pointed to by the $TERM variable. That's why you set it in the first place..!
In this respect, terminal/console Vim simply follows the *nix model and determines the terminal's capabilities from the terminfo entry and automatically sets the contents of the t_Co variable.
Tried and tested on something like 15 different terminal emulations in a GNU/linux environment.
t_Co
in your .vimrc, just put this line in your .bashrc:[[ -n "$DISPLAY" && "$TERM" = "xterm" ]] && export TERM=xterm-256color
– Putrescible$TERM
is set correctly,t_Co
automatically set to 256, but colors are still broken. – Marillin