Everyone has special and perhaps, particular, tastes when it comes to their code editor. There are literally thousands of themes out there, and for good reason: a thing of beauty and enhancement to productivity for one can be a hindrance to another.
It’s been an item on my bucket list to create my own theme. I was coding very late the one night, well into the small hours of the morning. Everyone in my house was sleeping and so, as usual, the only light was the glow of my screen. I know it’s not necessarily healthy to code like this, but it’s literally the time I’m most productive: there are minimal distractions, I’m not dealing with work stuff, family stuff, friend stuff, or puppy stuff. I can focus.
I had some preferences set for the theme I had been using and, though they all worked well for daytime or plane rides, I always felt like something was missing for late night coding sessions. I decided it was time to craft my own theme.
We’ll talk first about the general process for creating a theme in case you’d like to create one of your own, and then we’ll dive into some of the research and testing that went into mine in particular to peek into the process.
Fire It Up
Before you do anything, you’re going to install vsce (short for Visual Studio Code Extensions) and establish yourself as a publisher. All of the instructions to do so are here. I know it looks like a lot, but it takes anywhere from 5-10 minutes, and then you’ll never have to do it again, for any extension you create.
Now that you’ve got that under your belt, here are the steps you need to start work.
First, you need to run:
npm install -g yo generator-code
This makes the generator globally available on your machine (meaning you can now create a theme in any directory). You can then execute this command to kick off your theme:
You will be prompted by a screen that looks like this:
Note that I’ve used the arrows here to navigate to the “New Color Theme” option. Note also that this is how you’d want to make any other extension.
When selecting this, it asks if this is a new theme or if we want to import from an existing one. We want to create a new one.
Next, you’ll have to answer a few other questions, including:
- What’s the extension’s name?
- What is the the identifier? (I just went with the name, that’s probably typical.)
- What is the the description? (I just put something silly in initially. Don’t worry, you can update this in your package.json in the future.)
- What’s the publisher’s name? (See earlier instructions.)
- What name should be shown to the user? (I used the same as the extension name.)
- Is this theme dark, light, or high contrast?
It will set you up with a base theme to start skinning your color preferences. The full scoop and all the details are here. More details about themes in general are here.
We have our base theme and we have some concepts for the palette. So, how do we test it out? When you open the directory with your theme, you can press fn + f5 on Mac (or just f5 on Windows) and a new window immediately pops open where you can test your theme! You’ll see in the original theme window that you now have a little control panel where you can reload, pause, and stop. Don’t forget to save before you do!