Configuration Reference

Polyfont is configured via a .polyfont.toml file placed in your project root or home directory. The config loader searches upward from the current directory to find the nearest config file.

Top-level Schema

FieldTypeRequiredDefaultDescription
version integer required -- Config format version. Must be 1.
default table optional none Default font applied when no rule matches. Becomes the * catchall rule.
rules array of tables optional [] Array of font rules mapping scopes to fonts.

Default Font Section

The [default] section defines the fallback font for any token not matched by a rule. If specified, it becomes a catchall rule with scope *.

FieldTypeRequiredDefaultDescription
family string required -- Primary font family name. Must not be empty.
fallbacks string[] optional [] Fallback font families in priority order.
weight string optional "regular" Font weight. See weight values below.
style string optional "normal" Font style. One of normal, italic, oblique.
size number optional none Font size in points. Omit to inherit from the editor.

Font Rule

Each entry in the [[rules]] array maps a TextMate scope to a font specification:

FieldTypeRequiredDefaultDescription
scope string required -- TextMate scope selector. Must not be empty. Supports hierarchical matching, wildcards, and negation.
font.family string required -- Primary font family name. Must not be empty.
font.fallbacks string[] optional [] Fallback font families in priority order.
font.weight string optional "regular" Font weight. See weight values below.
font.style string optional "normal" Font style. One of normal, italic, oblique.
font.size number optional none Font size in points. Omit to inherit from the editor.

Font Spec Fields

Both the [default] section and each [rules.font] section share the same font specification fields. In TOML, font fields are nested under the rule:

[[rules]]
scope = "keyword"
[rules.font]
family = "Maple Mono"
weight = "bold"

Font Weight Values

TOML ValueCSS ValueNumeric
"thin"100100
"extra-light"200200
"light"300300
"regular"normal400
"medium"500500
"semi-bold"600600
"bold"bold700
"extra-bold"800800
"black"900900

Font Style Values

TOML ValueDescription
"normal"Upright (default)
"italic"Italic variant
"oblique"Oblique variant

Scope Matching Rules

Scopes use TextMate notation with hierarchical matching. Understanding these rules is essential for writing correct configurations.

Hierarchical matching

A scope pattern matches any scope that starts with the same segments:

PatternMatchesDoes not match
"keyword"keyword, keyword.control, keyword.operatorkeywordx
"entity.name"entity.name, entity.name.function, entity.name.typeentity.type
"entity.name.function"entity.name.functionentity.name.type

Wildcard

The * pattern matches every scope. When a [default] section is defined, it becomes a catchall rule with scope *.

Segment-level wildcards are also supported: "entity.*" matches entity.name, entity.type, and any child.

Specificity

When multiple rules match a scope, the most specific rule wins. Specificity is determined by the number of literal (non-wildcard) segments in the pattern:

PatternSpecificity
"keyword"1
"keyword.control"2
"entity.name.function"3
"*"1 (matches all, lowest priority)
"entity.*"1 (literal segments only)

If two rules have equal specificity, the rule that appears first in the config wins.

Negation

Prefix a scope pattern with - to exclude it from matching. Use commas to combine positive and negative patterns:

SelectorBehavior
"keyword,-keyword.operator"Matches keyword and keyword.control but not keyword.operator.
"entity,entity.name.function"Matches entity or entity.name.function (comma = OR).

All 17 Example Rules

These are the complete rules from polyfont.example.toml:

#ScopeFont FamilyWeightStyle
1keywordMaple Monobold--
2keyword.controlMaple Monobold--
3commentIBM Plex Mono--italic
4stringSource Code Prolight--
5string.quotedSource Code Prolight--
6entity.name.functionMonaspace Argonsemi-bold--
7entity.name.typeMonaspace Neonsemi-bold--
8variableJetBrains Mono----
9variable.parameterJetBrains Mono--italic
10constantMonaspace Radonbold--
11constant.numericMonaspace Radon----
12support.functionMonaspace Krypton----
13storage.typeMaple Monobolditalic
14punctuationFira Code----
15operatorFira Code----
16meta.tagMonaspace Xenonbold--
17attributeIBM Plex Mono--italic

Scope Reference

Common TextMate scopes used in programming language grammars:

ScopeDescriptionTypical Tokens
keywordLanguage keywordsif, else, fn, let
keyword.controlControl flow keywordsif, for, while, return
keyword.operatorOperator keywordsand, or, not
commentComments// ..., /* ... */
comment.lineLine comments// ...
comment.blockBlock comments/* ... */
stringString literals"hello", 'world'
string.quotedQuoted strings"hello"
string.quoted.doubleDouble-quoted strings"hello"
string.quoted.singleSingle-quoted strings'hello'
string.templateTemplate strings`hello ${name}`
entity.name.functionFunction namescalculate_total
entity.name.typeType namesMyStruct, MyEnum
entity.name.tagHTML/XML tags<div>
entity.other.attribute-nameAttribute namesclass, id
variableVariablescount, result
variable.parameterFunction parametersitems, name
variable.otherOther variableslocal_var
constantConstantsMAX_SIZE, PI
constant.numericNumeric literals42, 3.14, 0xFF
constant.languageLanguage constantstrue, false, null
support.functionBuilt-in/library functionsprintln, len
support.typeBuilt-in typesString, Vec
storage.typeType annotations/declarationsi32, String
storage.modifierStorage modifiersmut, const, static
punctuationPunctuation characters(, ), {, }
punctuation.separatorSeparators,, ;, .
operatorOperators+, -, ==, &&
meta.tagTags (HTML/XML)<div>
attributeAttributeshref, class