How to Turn On or Off Color Syntax Highlighting In vi or vim Editor

How do I turn on or off color syntax highlighting in vi or vim text editor on a Linux or Unix-like operating system?

Vim or vi is a text editor. It can be used to edit all kinds of plain text files, editing programs, and UNIX/Linux configuration files. Vim supports additional options and it includes a lot of enhancements above old good vi text editor.

Syntax highlighting is nothing but a feature of vi/vim text editors that displays text, especially source code, in different colors and fonts according to the category of terms.

Task: Turn on color syntax highlighting

Open a file, for example open existing file called file.c, enter:

$ vi file.c

Now press ESC key, type “: syntax on” i.e. type as follows:

:syntax on

Task: Turn off color syntax highlighting

To turn it back off, press ESC key, type : syntax off

:syntax off

How do I make the syntax highlighting permanent?

You can edit ~/.vimrc file and add append vim command syntax on to it. This ensures that vim will start with color syntax highlighting option:

$ cd
$ vi .vimrc

Append the following line:

syntax on

set nu

Save and close the file.

http://www.cyberciti.biz/faq/turn-on-or-off-color-syntax-highlighting-in-vi-or-vim/