Package Control

The official Sublime Text package manager.

SubCalc

Calculate with variables right inside Sublime Text

By vonbehr
Created September 8, 2026, last updated September 17, 2026.

AugJulJunMayAprMarFebJan Dec2025 NovOctSep 2026-W38 | installs: 1 | removals: 0 | upgrades: 0 2026-W38 | installs: 1 | removals: 0 | upgrades: 0 2026-W38 | installs: 1 | removals: 0 | upgrades: 0 024 WeeklyInstalls 024 WeeklyUpgrades 2026-W38 | upgrades: 0 1.1.0 2026-W37 1.0.0
Installations: 1 in total
Installations minus removals
Upgrades

Links

Versions

1.1.0 (>ST4049) ·
2026-09-17 18:32

More
  • (>ST4049) 1.0.0 ·
    2026-09-08 13:53

SubCalc

A Sublime Text 4 package for live, per-line calculation in plain-text notes.

Write a .calc file mixing prose and math; every line that evaluates to a number shows its result inline as you type. Lines that aren't calculations are left alone.

Example

Grocery budget
rent = 1200                                      ⟶ 1200
groceries = 350                                  ⟶ 350
rent + groceries          // total fixed costs   ⟶ 1550
line4 - 10%                                      ⟶ 1395
20% of 1550                                      ⟶ 310

A quick tour of the rest -- functions, units and currency, dates and times, and the total aggregate:

sqrt(2)                     ⟶ 1.414214
round(pi * 2, 2)            ⟶ 6.28
max(12, 7, 20)              ⟶ 20

5 km + 200 m                ⟶ 5.2 km
45 USD + 12.50 USD in EUR   ⟶ 62.5 EUR

2026-01-01 to 2026-06-01    ⟶ 151 days
14:30 + 90 min              ⟶ 16:00

10                          ⟶ 10
20                          ⟶ 20
total                       ⟶ 30

More worked examples -- functions and math, unit conversion, currency, dates and times, an invoice -- live in examples/.

Syntax

Customizing colors

SubCalc doesn't ship a color scheme -- it just adds standard TextMate scopes suffixed with .calc to the syntax, so highlighting falls back to whatever your current color scheme already defines for the base scope (constant.numeric, keyword.operator, variable.other, comment.line, etc.).

To style the SubCalc-specific scopes distinctly, add rules for them to your own color scheme via Preferences > Customize Color Scheme… (this creates an override file in Packages/User/ that layers on top of your base scheme without replacing it):

{
    "rules": [
        { "scope": "constant.other.date.calc, constant.other.time.calc", "foreground": "#e5c07b" },
        { "scope": "support.function.calc", "foreground": "#61afef", "font_style": "bold" },
        { "scope": "keyword.other.calc, keyword.operator.word.calc", "foreground": "#c678dd" },
        { "scope": "constant.language.calc", "foreground": "#d19a66" },
        { "scope": "variable.other.label.calc", "foreground": "#56b6c2", "font_style": "italic" },
        { "scope": "variable.other.assignment.calc", "foreground": "#e06c75", "font_style": "bold" },
        { "scope": "keyword.operator.unit.calc", "foreground": "#98c379" }
    ]
}

See Sublime's color scheme docs for the full mechanics of per-user overrides.

Commands

Available from the command palette (and Edit > SubCalc in the menu):

Hovering a variable, #label, or lineN shows a popup with its current value, and they're all offered as autocomplete suggestions, alongside function and keyword names. Selecting more than one line's worth of text shows that selection's total and average in the status bar.

Live currency rates (optional)

By default, currency conversion ($5 in EUR, etc.) uses a small static table baked into the package, which only gets updated when the package does. Setting "currency_live_rates": true in Calc.sublime-settings switches to real exchange rates instead: SubCalc fetches them in the background from Frankfurter (a free, no-API-key service backed by European Central Bank reference rates), caching the result for currency_cache_minutes (an hour, by default) before fetching again.

This is the only thing in SubCalc that touches the network, it's off unless you turn it on, and it only ever requests exchange rates — never anything from your files. A fetch never blocks typing: it runs in the background, and until it completes (or if it fails, e.g. you're offline) SubCalc keeps using the last rates it has, static or previously fetched. Run SubCalc: Refresh Currency Rates any time to fetch immediately, regardless of the setting.

currency_api_url points at a different endpoint if you'd rather use another provider or self-host one — it just needs to return JSON shaped like {"rates": {"EUR": 0.92, "GBP": 0.79, ...}}, expressed relative to USD.

Installing locally (not yet on Package Control)

Symlink this repo into Sublime Text's Packages directory.

macOS

ln -s "$(pwd)" "$HOME/Library/Application Support/Sublime Text/Packages/SubCalc"

Windows

Find your Packages directory via Sublime Text's Preferences > Browse Packages… (typically %APPDATA%\Sublime Text\Packages), then create the symlink from a PowerShell prompt running as Administrator:

New-Item -ItemType SymbolicLink `
    -Path "$env:APPDATA\Sublime Text\Packages\SubCalc" `
    -Target "C:\path\to\this\repo"

Alternatively, from an Administrator Command Prompt:

mklink /D "%APPDATA%\Sublime Text\Packages\SubCalc" "C:\path\to\this\repo"

A symlink is required (rather than a plain copy) so that Sublime Text picks up further changes to this repo without reinstalling.

Then, in Sublime Text, open the command palette and run SubCalc: New Calculation (or create/open any file with a .calc extension).

Settings (Calc.sublime-settings, accessible via Preferences > Package Settings) let you tune the decimal precision, thousands separator (,/./off) and decimal separator (./,, must differ from each other), result prefix, rounding mode (half_even/half_up/floor/ceil), debounce delay, and live currency rates (see above).

Development

See CONTRIBUTING.md for dev setup (tests, lint, type checks, pre-commit) and style guidelines, and ROADMAP.md for planned work.

The calculation engine (engine/) is pure Python with no dependency on Sublime's sublime/sublime_plugin modules, so it's fully testable outside the editor:

python3 -m venv .venv && .venv/bin/pip install pytest
.venv/bin/pytest

Only SubCalc.py (the editor-integration layer) requires manual testing inside Sublime Text, since the sublime module only exists there.

Results

Packages