I’ve been using Sublime Text as my main text editor since August of 2014. I know it pretty well, but occassionally I still learn something new and useful.

Today I learned about the Arithmetic command from a video by OdatNurd.

Summary of what I learned

Variables

The following variables are supported:

VariableWhat it does
sThe literal selected text
iThe selected text interpreted as a number (0, if interpretation fails)
iThe index of each selection (0-indexed)

Converstions

hex(x) // to hex
int(x) // to decimal
bin(x) // to binary

format() is supported

format(x, ',')   // add comma separators to number, 1234 -> 1,234
format(x, '^80') // center selected text in 80-character column

math package is supported

math.ceil(x)
math.floor(x)

TIP: Update numbers of an ordered list

This is particularly useful; I do this all the time!

  1. Select each number, split selection to lines
  2. Open Command Palette... > Arithmetic
  3. Enter: i+1
  4. Done!