See Also

Syntax highlighting

Syntax highlighting is a feature of some text editor Text editor

A text editor is software application [i] used for editing plain text [i]. ... 

s that displays text—especially source code Source code

Source code is any series of statements written in some human-readable [i] computer programming language [i] ... 

—in different colors and font Typeface

In typography [i], a typeface consists of a coordinated set [i] of glyph [i]s designed with stylistic un ... 

s according to the category of terms. This feature eases writing in a structured language such as a programming language Programming language

A programming language is an artificial language [i] that can be used to control [i] ... 

 or a markup language Markup language

A markup language combines text and extra information about the text.... 

 as both structures and syntax errors are visually distinct. Some editors also use syntax highlighting as part of an integrated spell checking Spell checker

In computing [i] terms, a spell checker or spelling checker is a design feature or a software [i] ... 

 and/or code folding feature. When looking at pages and pages of code, syntax highlighting greatly improves the readability and context of the text.

Discussions

  Discussion Features

   Ask a question about 'Syntax highlighting'

   Start a new discussion about 'Syntax highlighting'

   Answer questions about 'Syntax highlighting'

   'Syntax highlighting' discussion forum


Encyclopedia



Syntax highlighting is a feature of some text editor Text editor

A text editor is software application [i] used for editing plain text [i]. ... 

s that displays text—especially source code Source code

Source code is any series of statements written in some human-readable [i] computer programming language [i] ... 

—in different colors and font Typeface

In typography [i], a typeface consists of a coordinated set [i] of glyph [i]s designed with stylistic un ... 

s according to the category of terms. This feature eases writing in a structured language such as a programming language Programming language

A programming language is an artificial language [i] that can be used to control [i] ... 

 or a markup language Markup language

A markup language combines text and extra information about the text.... 

 as both structures and syntax errors are visually distinct. Some editors also use syntax highlighting as part of an integrated spell checking Spell checker

In computing [i] terms, a spell checker or spelling checker is a design feature or a software [i] ... 

 and/or code folding feature.

When looking at pages and pages of code, syntax highlighting greatly improves the readability and context of the text. The reader can automatically ignore large sections of comments or code, depending on what one desires.

Syntax highlighting also helps programmers find errors in their program. Often, most editors highlight string literals in a different color so one is able to see if they have left out a closing quotation mark just by looking at the color of the text.

Brace matching is another important feature with many popular editors. This makes it simple to see if a brace has been left out or locate the match of the brace the cursor is on by highlighting the pair in a different color.

For editors that support more than one language the user can specify the language of the text, such as C C (programming language)

The C programming language is a general-purpose, procedural [i], imperative [i] ... 

, LaTeX LaTeX

,
written as LaTeX in plain text, is a document preparation system [i] for the
... 

, HTML HTML

In computing, HyperText Markup Language is a predominant markup language [i] for the creation of web page [i] ... 

, or the text editor can automatically recognize it based on the file extension or by scanning contents of the file.

Most editors with syntax highlighting allow different colors and text styles to be given to dozens of different syntactic categories. Programmers will often heavily customize their settings in an attempt to show as much useful information as possible without making the code difficult to read.

Some text editors can also export the color markup in a format that is suitable for printing or for importing into word-processing and/or text-formatting software; for instance a HTML, colorized LaTeX, PostScript PostScript

PostScript is a page description language [i] and programming language [i] used primarily in the electr ... 

 or RTF version of its syntax highlighting.

Example


Below is a snippet of syntax highlighted C++ C++

C++ is a general-purpose, high-level [i] programming language [i] with low-level [i] facilities. ... 

 code:

// Allocate all the windows
for


In this example, the editor has recognized the keywords for, int, and new. It recognized the variable names i, wins, and max and highlighted them accordingly. The comment before the code is also highlighted in a specific manner to distinguish it from working code.

Limitations


Since most text editors highlight syntax based on complex pattern matching heuristics rather than actually implementing a parser for each possible language, which would be prohibitively complex, the highlighting can never be one hundred percent accurate. In addition, due to the nature of pattern matching the highlighting "engine" can become very slow for certain types of language structures. Some editors overcome this problem by not always parsing the whole file but rather just the visible area, sometimes scanning backwards in the text up to a limited number of lines for "syncing."

See also


  • The Programming features section of the Comparison of text editors article for a list of some editors that have syntax highlighting.