Controlling Linux colors in vi (vim)

Got questions? Go ahead: Ask me anything!

Because of an old application that apparently partially looks at termcap and partially hard-codes terminal info, a customer has to set TERM=ansi when using Alphacom to access his Linux box.

The Linux colorizing fouls things up royally. You can shut off command line colorizing by editing /etc/DIR_COLORS and changing "COLOR tty" to "COLOR none" or (less drastically) by removing the "TERM ansi" line from the same file (which removes colorization for ansi but doesn't affect console use).

But that still leaves vi messing things up. The fix for that is to add

set t_Co=0 
# t_C0=2 turns off MOST colors, 0 kills all

to the top of /etc/vimrc. I attempted to do this in ~/.vimrc but couldn't make it work, and also tried

if &term=="ansi" 
  set t_Co=0 

in /etc/vimrc but that didn't work either.. not sure why yet. The idea there would be to let vim colorize if not using ansi, though in my case forcing it is fine because I don't want colors in vi ever.

I have seen the suggestion to "set syntax off"; that didn't work for me or the customer. I also tried using the "nosyntax.vim" file in /usr/share/vim/vim63/syntax, and even downloaded a "black and white" color scheme from, but vim still stubbornly would show colors for errors. Only the t_Co=0 worked.

To my mind, colorizing is pretty messed up..

Also see Linux shell colors; shell ls colorization.

Got something to add? Send me email.

(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Controlling Linux colors in vi (vim)


Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Tony Lawrence

Mon Mar 14 20:22:47 2005: 177   TonyLawrence


Frustratingly, the person who originally had this problems says that his screen still turns blue in vi.. with Alphacom, but not Powerterm.. makes no sense to me, but we'll ask the Alphacom folks if they can shed any light on this..

Wed Mar 16 20:42:38 2005: 184   TonyLawrence


Just the difference between t_Co=0 and t_Co=2

Sat Sep 24 23:00:56 2005: 1120   BigDumbDinosaur

I personally find vim's use of text colors real annoying, primarily because I'm partially color-blind. On my SCO box (which is where I still do a lot of my work) I either work in monochrome (usually green on black -- old habits die slowly) or have set text colors that are high contrast and do not mix blues and greens (my color-blindness is the relatively rare blue-green type -- most color-blindness is red-green). The widespread use of blue backgrounds in applications poses a real problem for me, as combinations like black on blue, light green on blue and so on are barely visible to me. The page borders displayed on this site when running in border mode are almost invisible relative to the white background of the main frame. Another visually annoying application I use is Microlite's Backup Edge. The default color combination (blue background, white foreground) results in an eye-watering session.

Mon Jun 26 05:42:59 2006: 2168   anonymous

this works on an ad-hoc basis:
:syn off

Tue Aug 22 04:23:14 2006: 2423   anonymous

I too am colorblind (juts red-green here). As if that's not bad enough, I am ADHD too. The colors are not only annoying but incredibly distracting. Just give me my text--nothing fancy, just good ol' vi!

Wed Jan 3 17:16:44 2007: 2800   vp70

do following to change color highlighting for comment from darkblue (default) to darkgray

if &term=="rxvt"
set term=xterm
if &term=="xterm" || &term=="rxvt"
set t_Co=8
map ,u :source ~/.vimrc<CR>
syntax enable
hi Comment cterm=none ctermfg=darkgray ctermbg=none

Thu Jan 11 03:23:30 2007: 2809   anonymous

I agree that color in
vi is messed up at least on my redhat linux system in an xterm. Sorry, but I did not find the suggestion here helpful. Exactly where does one type the magic "set t_Co=0" ?

However, for straight up vi (i.e. not vim) , the suggestion here worked like a charm.


Thanks for a great and helpful site and forum.

Thu Jan 11 11:59:01 2007: 2810   TonyLawrence


You add it to /etc/vimrc

How can you say it didn't work if you didn't know where to add it? :-)

That link you gave is just the "set syntax off", which as I said above didn't work for me. I think that shows how screwy vim is: one thing works for you, the other for me. It's a messed up thing.

Fri Feb 1 21:07:38 2008: 3573   RichardBronosky

Vim is perfect. We are flawed. Anytime I think Vim has a problem, I find that I am wrong about 6 months later.

Fri Feb 1 22:28:06 2008: 3576   TonyLawrence


Well, I'm a big vi fan - every single page I post here was written with vi - but it does have its faults just the same :-)

Tue Jun 29 10:36:57 2010: 8757   anonymous


Especially the dark blue comment colouring on a black background is unreadable. I have changed first
set background=dark, which makes all comments light blue. The syntax colouring is fine for me and at least I don't have to fix my eyes on the deep blue comments. Works for me

Wed Apr 13 12:04:54 2011: 9455   geedoubleya


Thanks anonymous, that has revealed the logical cause of all my colour issues in vim as I have always reversed the default terminal emulator colour scheme from black on white, and wondered why the commented lines are in such an odd colour. Let vim know that you have done this by by applying set background=dark and all is could I miss such simplicity!

Kerio Samepage

Have you tried Searching this site?

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. ((Edsger W. Dijkstra)

This post tagged: