Saturday, May 31, 2008

How to disable vim syntax highlighting and coloring

Syntax highlighting is my top annoyance in using vi/vim. Syntax highlighting is just a fancy term meaning that the text editor will auto-color parts of a text file according to some rules that makes sense to it, using some default color scheme.

To be precise, only vim, not vi, has syntax highlighting. vi has a 2 color scheme only: background and foreground. Yet, on my Centos 4 system (and many other distros), the vi command is just a soft link to vim.

Syntax highlighting is useful, and usually nothing to complain about. However, I find the default vim color scheme to be an eye-killer for me.

If you are already in vi/m, you can disable it by typing
:syntax off (and press the return key).

To re-enable coloring, type
:syntax on (and press the return key).

If you want to permanently disable syntax highlighting, insert this in your ~/.vimrc file:
syntax off

Note that even with vim, there can be different versions. On my Debian Etch system, the vim is vim.tiny, and it does not support syntax highlighting. So, you don't need to explicitly disable syntax highlighting.

StumbleUpon Toolbar


Sync said...

Turns out there's an inordinate amount of bogus crap that goes on in vim in this regard, and "syntax off" is insufficient to disable it all. Try these in your .vimrc as well:

syntax off
let g:loaded_matchparen=1
set nocp
set noincsearch
set nohlsearch
set noshowmatch

These will turn off the annoying highlighting behaviors with matching brackets, search matches, and the horrendous "interactive" search. vi wasn't broke, I don't know why they insist on the feeping creaturism in this monster called "vim" or what made them think it was sufficient to replace the original vi.

Anonymous said...

HURRAH!!! No more bleeding eyes and cursing at the screen, and best of all, I can use vi on Linux again, instead of having to bail for (insert different editor here)! Thank you, thank you, thank you!

SWD said...

The advice in this blog posting is very helpful. But I'm still having a problem with line numbering. If I do ":set number" the line numbers are almost illegible. Given that there must be many people who, like me, have difficulty distinguishing certain colors, I'm surprised there isn't a overarching accessibility setting to tell vi/vim to use just one color.

Nerdmaster said...

You know, you can change color schemes pretty easily.... Syntax highlighting (for me) is too critical to drop just because the default scheme isn't what I want.

Anonymous said...

You can also put something like this in your .bashrc to get the genuine vi feeling :-)

export EXINIT="syntax off set ai redraw terse warn sw=4 sm nocompatible"

Geoffrey McRae said...

Under Debian with a dark/black background the default scheme sucks, it is too dark, but if you uncomment the line in /etc/vim/vimrc "set background=dark your syntax highlighting is nice and bright :)