On Syntax Highlighting

Author

Max Bucknell

Published

February 2, 2025

A screenshot of the Zed text editor, showing some Rust source code in a dark colour scheme

I roll my own colour scheme for any text editor I use. I don’t do this because I’m fussy and no off-the-shelf colour scheme will do (although I am fussy), I do this because I have a very particular manner of highlighting syntax, regardless of the exact colours I’m using. I’ve received a fair bit of inquiry from friends and colleagues about why I do this, and I’ve never seen anyone else do exactly what I do, so I decided I should write it down while I’m thinking about it. (I’m thinking about it because my team and I are trying out Zed for pairing and remote collaboration, so I’ve had recently had to do this dance.) As it happens, I am in fact using my own custom colour scheme as well. I know just enought colour theory to be dangerous, and I had a few specific requirements that other colour schemes weren’t meeting, and I had to do all this anyway, and it’s not that hard. Some might even say it’s fun. But that is a tale for another time. What I want to write about today is not the specific selection of colours I use, but the manner in which I use them.

When I was a kid, I initially learned to code in Notepad. When I first got my hands on some actual editor (I think it was Dreamweaver), I was amazed mostly by syntax highlighting. For the first time, code looked cool. I never understood what the different colours meant, but it did make the entire thing look like a fidget toy, which was extremely up my alley. As I got older, I began to take this coding thing more seriously, and for most of my teenage years I was devouring everything I could find about software development. This included a lot of discussion about tools, and a lot of this really left its mark on me. Sometime around 2009 I started to use Vim for the first time. Some time in 2011 I switched to the Dvorak keyboard layout. I really tried everything. Some of it stuck; some of it didn’t. One thing in particular did take hold in me, though: at some point, I turned off syntax highlighting in Vim.

Exactly when I did this, and exactly what prompted me are sadly lost to the sands of time. I think it was a Damon Conway conference talk about his 1500 line Vimrc, but I could not find such a talk online that predates the initial commit of my Vimrc in my dotfiles, which was over a decade ago. And even by then I had moved on from :syntax off to something more sophisticated. To, as it happens, an early version of the same syntax highlighting scheme that I use to this day. Regardless of where I heard this or who told me, someone advertised that they do not use syntax highlighting, because they find it overwhelming and useless. This resonated with me, because I still didn’t understand what it all meant. So I tried turning it off, and I liked it. But living without syntax highlighting did force me back to first principles, and I ended up pulling a few things back into my life. They haven’t really changed in the last ten years.

Get in the comments

At a similar time, during a debate on the merit of code comments (if this entire blog post were not evidence enough, take it from me directly that I find it difficult to resist discussions as to the colour or colours in which to paint the bikeshed) somebody asked how we are supposed to take comments seriously when our text editors themselves dim them out relative to the background. They are, almost by definition, less unimportant.

This didn’t work on me, of course, my comments looked exactly like the rest of my code. But it did resonate. My general position here is that if somebody goes out of their way to write some prose inside some code, it’s probably important, and so I want to pay attention to it. Moreover, I don’t want to refactor something and miss a comment, left to go stale. In the best case, a stale comment is useless. Somewhere in the middle it is misleading, and in the worst cases can be downright dangerous.

So I made comments green. This was a real bummer for me, because I had to :syntax on, and then I had to build a whole-ass colour scheme in Vim that disabled everything, and then made comments green (ctermfg=2). But I did it, and by then I had eaten from the tree of knowledge of good and evil: syntax highlighting was back on the menu.

A little bit more colour

Since I had the power, it was pretty easy to then make Vim chrome red (status bar, split lines, and so on), and search results blue. The exact colours used here have chopped and changed over the years, but currently search is still blue (it was yellow for a while though), and Vim chrome is purple.

Literally though

I stayed like this for a while, until I had my first (in this story at least) original idea: hardcoding things is bad. There’s nuance here, but in general I consider factoring things into variables good, and not doing so to be vaguely harmful. That’s not the original idea. The original idea was that I could highlight literal expressions in my code, so that a visual scan can find an overuse of them.

Thus, I made scalar expressions cyan. The exact timing of this is not lost to the sands of time, it was almost exactly ten years ago, on 11th January 2015.

Just like that, ten years goes by

And that’s about where we are today. I went from Vim to NeoVim, there was definitely some Jetbrains shenanigans in there. I went from NeoVim to Nova, then to Zed. I liked Zed’s vim mode so much that I switched back to Vim last year, and now I’m somewhere in between Vim and Zed.

But my syntax highlighting, that stays with me. Here it is, in light mode.

A screenshot of the Zed text editor, showing some Rust source code in a light colour scheme