JetBrains IDEs hidden features: Syntax Highlighting

JetBrains has added powerful improvements to their IDE over the years, but leaves some features disabled in the default configuration. If my colleagues are representative, most users don’t know these features exist.

Here, we’re going to look at syntax highlighting. The default schemes only assign colors to a few token types. My goal is for you to be aware of the token types that are available, and to customize more of them.

And JetBrains, I want you to help change the defaults!

What’s off?

Here’s what the code looks like with IntelliJ’s default light theme.

And here’s what it looks like with my light theme.

And here’s my dark theme.

TL;DR

If you want to know what the colors mean, read on.

Color Semantics

Foreground colors for concrete and abstract

  • Interfaces are teal
  • Concrete classes are maroon
  • Abstract classes are maroon with a teal underline

Method calls are underlined with teal if the method is defined in an interface.

Method calls are underlined with maroon if the method is defined in a superclass.

Italics and bold for static and mutability

I use bold to represent mutability. This can help when stepping through code in the debugger. Only the bolded names can have their values change over time.

  • Fields that are non-final, both static and non-static, are bold
  • Parameters that get reassigned are bold
  • Variables that get reassigned are bold, including loop variables

Background colors for errors

Differences from defaults

Foreground colors

The default themes have custom foreground colors for keywords, fields, numbers, and string literals. I’ve kept these colors unchanged in my themes.

Italics and bold

IntelliJ Light doesn’t use bold. Classic Light uses bold for keywords, instance fields, and static final fields, but not static non-final fields.

If there is some meaning behind bold in this theme, I haven’t figured it out.

Errors and warnings

Errors and weak warnings use underwaves. Warnings use a background color.

Text decorations can shadow each other.

Here, the underline for reassignment is obscured by the underwave for the type error.

Configuration

  • Open the IDE settings, go to Settings > Editor > Color Scheme.
  • Choose a built-in scheme, like IntelliJ Light or Darcula.
  • Click the gear icon, and choose Duplicate…
  • Give it a name and choose Apply.

Next it’s helpful to look at a specific language. I’ll click Java.

Quick config

Clicking param1 jumps to the settings for Parameters

This makes it easy to discover the various token types, and can make it quick to set up a new color scheme. However, we usually don’t want to apply our config here at the “leaves” of the tree.

Config tree

  • Java > Constant (static final imported field)
  • Java > Constant (static final field)
  • Java > Static field
  • Language Defaults > Static field
  • Language Defaults > Default
  • General > Default text

It’s best to configure the token types as high in the hierarchy as possible, in “Language Defaults” or “General” whenever possible. Settings here will apply to all programming languages, which is especially helpful when working with a new language.

Let’s say we’re not too familiar with Scala code and we come across a trait.

We can see that trait is a keyword and the name is highlighted teal, a strong hint that traits are similar to interfaces.

Out of the box, my themes work pretty well for Scala.

With a bit of language-specific tweaking, we can make our themes even better. If we can keep the tweaks to a minimum, we will have a consistent experience across languages.

Conclusion

See my other post if you’d like to know more about how I picked specific colors.

What other features are chronically underused, because the IDE has them disabled by default?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store