Q: Vim doesn't display colors I run a Debian 7.8 server, installed all vim packages I could think of.
My .profile contains:
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
        export TERM='xterm-256color'
else
        export TERM='xterm-color'
fi

My .vimrc contains:
set t_Co=256
set t_AB=^[[48;5;%dm
set t_AF=^[[38;5;%dm

And yet when I open a random cpp files and set :syntax on I don't get any colors, but this:
^[[38;5;14m//#include <unistd.h>
^[[38;5;81m#include ^[[38;5;13m"bouchonWifi.h"
^[[38;5;81m#include ^[[38;5;13m"string.h"

I've checked that my terminal can display colors thanks to a perl script that shows all 256 colors, ls is colored...
How to get colors to display properly in vim?

A: Try this:
if !has("gui_running")
    if &term == 'dterm'
        set tsl=0 " Sun's terminal sucks bigtime
    elseif has("terminfo") && ! (&term == 'linux' || &term == 'Eterm' || &term == 'vt220' || &term == 'nsterm-16color' || &term == 'xterm-16color')
        " Force these terminals to accept my authority! (default)
        " number of colors
        set t_Co=16
        " ANSI background
        set t_AB=^[[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
        " ANSI foreground
        set t_AF=^[[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
    elseif &term == 'term' || &term == 'rxvt' || &term == 'vt100' || &term == 'screen'
        " Less-Cool Terminals (no terminfo)
        set t_Co=16
        set t_AB=^[[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
        set t_AF=^[[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
    else
        " Terminals that have trustworthy terminfo entries
        if &term == 'vt220'
            set t_Co=8
            " foreground
            set t_Sf=^[[3%dm
            " background
            set t_Sb=^[[4%dm
        elseif $TERM == 'xterm'
            set term=xterm-color
        endif
    endif
endif


" enable filetype detection
if version >= 600
    filetype plugin indent on
else
    filetype on
endif
" make sure we have colors first
if &t_Co > 2 || has("gui_running")
    syntax on
endif

