Fix missing Droid monospace fonts in VSCode, VSCodium and Sublime on Ubuntu and Debian

Today I noticed that my usual code editors had stopped displaying code in monospace. Here is a quick fix to get that working again.

Monospace fonts are a huge help when editing code, as they make it much simpler to follow the vertical alignment of code at a glance. This is useful for whitespace-agnostic languages such as JavaScript, PHP, C++ etc, and essential for whitespace-dependent languages such as Python.

The underlying cause of the problem seems to be that Google have stopped updating the Droid font families, and therefore Debian and Ubuntu no longer provide packages for them. Debian and Ubuntu still provide a package fonts-droid-fallback, but for whatever reason it wasn't picked up on my system despite being installed. VSCodium (and probably also VSCode) has the default font setting "'Droid Sans Mono', 'monospace', monospace". Since I observed the same problem in Sublime Text 4, I suspect it has a similar default. I’ve no idea why the monospace fallback didn’t work, but in both VSCodium and Sublime the default code rendering had switched to a variable width font. I expect that both code editors will fix this upstream at some point, but in the meantime I wanted to quickly get my monospaced fonts back with a minimum of fiddling around.

In VSCode or VSCodium, you can do this by pressing <Ctrl> + , to open the preferences dialog, find the Editor: Font Family setting, and change the first option to a monospace font that you have installed on your system. In Sublime Text 4, select Preferences → Settings in the top menu bar, and add a line "font_face": "Name Of Font", into the JSON configuration object, then save the file.

Once this issue is eventually fixed upstream, you can change back to the default as follows: In VSCodium/VSCode, open the preferences with <Ctrl> + ,, find the setting Editor: Font Family, click the cog icon to the left (it’s hidden until you hover over it), and select “Reset Setting”. In Sublime Text 4, select Preferences → Settings in the menu, and remove the "font_face": "Name Of Font", line, then save the file.

After trying a few options, I settled on Bitstream Vera Sans Mono. Bear in mind that you need to write the name of the font to correctly match the system name, including spaces between the words and no leading/trailing whitespace. You can see a list of your installed fonts by (for example) opening LibreOffice and checking the list of fonts in the text style dropdown. When choosing a font for coding, the first thing I check is that the glyphs for 1 (number one), l (lower case letter “ell”), I (upper case letter “eye”) are distinguishable, and likewise for 0 (number zero) and O (upper case letter “oh”). After that I think about the aesthetics.


An update to the article. On my system, not only was Droid Sans Mono no longer present due to being removed from the package repositories, the default monospace fallback was not working properly. I verified this by running fc-match monospace, which returned DejaVuSans.ttf: "DejaVu Sans" "Book". I'm not sure what caused this, but I was able to fix it by creating a file /etc/fonts/local.conf with the following contents:

<match target="pattern">
    <test name="family" qual="any">
    <edit binding="strong" mode="prepend" name="family">
        <string>DejaVu Sans Mono</string>

After that I ran sudo fc-cache -f to rebuild the font cache. The monospace family was then correctly set, fc-match monospace returned DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book".

This might have been a problem specific to my system, as I couldn't find any existing bug reports describing the same issue, although there were a number of similar ones. Most commonly affected programs seemed to VSCode and Firefox, although in this case it was an underlying system issue. This Stack Exchange post was helpful in working round the problem.

Claudemir - Fri, 14/07/2023 - 19:57


You saved my day. I don't know how I found your article. But thanks my friend!

Add new comment