Using Scope-Based Code Highlighting

Posted on by Yann Cébron

One of not so well-known features of IntelliJ IDEA is an ability to differently highlight certain scopes in code editor.

To use it, open the Settings dialog, under IDE Settings expand Editor, then expand Colors & Fonts, and select Scope Based preferences. You will see a list of predefined scopes, and the Edit Scopes button that lets you easily create your own.

Each scope is assigned a distinct color/font scheme — just like different language elements in Java, which makes it easy to distinguish from other code in the editor.

In the following example, it is used to quickly differentiate between real testing code and JUnit Classes (pattern: lib:org.junit..*):

Other use cases include highlighting of, for example, third-party framework code, distinguishing normal code from assertions, etc.

Comments below can no longer be edited.

3 Responses to Using Scope-Based Code Highlighting

  1. Eugene Kirpichov says:

    May 10, 2009

    Thanks, this is awesome. I’ll definitely be using this feature a lot.
    Why not include it into the Tips at startup?

  2. Esko Luontola says:

    May 29, 2009

    Some other highlightings that I’ve found useful are “Reassigned local variable”, “Reassigned parameter”, “Interface”, “Abstract class” and “Type parameter”. My color choices are at http://github.com/orfjackal/idea-config/tree/idea81/colors

  3. RobB says:

    March 26, 2014

    I was just looking for a way to discriminate between project and library code and found this. Perfect.

Subscribe

Subscribe for updates