Saturday, 9 September 2017

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

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

Posted onOctober 30, 2006in Categories last updated October 26, 2015
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
C source code editing while syntax highlighting is on in vi or vim:
Fig.01: Turn on or off color syntax highlighting in vi or vim
Fig.01: Turn on or off color syntax highlighting in vi or vim

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
Save and close the file.

No comments:

Post a Comment