# vi syntax coloring



## loves_the_IIsi (May 15, 2006)

Hi all, 

Does anyone know how to get syntax highlighting in vi? I've found a few descriptions of how to do it, but I can't seem to get it working. A couple weeks ago it randomly started showing colors, and then a few days ago it didn't do that anymore. What the heck did I do that would have changed it?

thanks


----------



## macbri (May 16, 2006)

loves_the_IIsi said:
			
		

> Hi all,
> 
> Does anyone know how to get syntax highlighting in vi? I've found a few descriptions of how to do it, but I can't seem to get it working. A couple weeks ago it randomly started showing colors, and then a few days ago it didn't do that anymore. What the heck did I do that would have changed it?
> 
> thanks



Hi - do you have a ~/.vimrc file?  Is not, create it, and make sure it contains the line:


```
:sy enable
```

Then launch vi again and see what ya get.  I also have my TERM env variable set to xterm-color, although my foggy brain seems to recollect that's to enable colour output with $LS_OPTIONS....


----------



## loves_the_IIsi (May 16, 2006)

hmm, I didn't have that file, but I did add it and that line, but that didn't seem to work either. I also have my TERM set to xterm-color, which I thought had something to do with it, but I guess maybe not.


----------



## Garulfo (Jun 5, 2006)

This should be a better solution :
in your .vimrc file write these lines


```
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif
```

I've copied this from my file (made from an example of Bram Moolenaar)


----------

