I just updated an extension, Find and Transform, that can do math on inserted text. With this simple keybinding (in keybindings.json
):
{
"key": "alt+r", // choose your keybinding
"command": "findInCurrentFile",
"args": {
"replace": "[$${ return ${CURRENT_HOUR} - 1 }$$:${CURRENT_MINUTE}]"
}
Since there is no find
, it will just insert the replace where your cursor is (as long as that cursor(s) is not in or right next to a word).
This part $${ return ${CURRENT_HOUR} - 1 }$$
indicates a javascript operation $${ <some operation here> }$$
which in this case gets the current hour and subtracts 1 from it.

You could also use a replace
like this:
"replace": [
"$${",
"const date = new Date();",
"return new Intl.DateTimeFormat('en-GB', { dateStyle: 'full', timeStyle: 'long' }).format(date)",
"}$$"
]
which would insert this at the cursor:
Tuesday, 22 February 2022 at 00:04:52 GMT-7
Previous answer using a macro extension to run multiple commands:
Generally there is no way to do math on a snippet variable without a truly ugly conditional replacement transform. However, some brilliant guy figured out a way to do simple increment/decrements by 1 (or 10 or 0.1 or multiples and combinations of those!).
See How to increment a variable, like the line number, in a vscode snippet in particular and also Find number and replace + 1. {But no one seems to have noticed.]
In your case, suing the macro extension multi-command put this into your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.decrementHourInSnippet",
"sequence": [
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "[$CURRENT_HOUR"
}
},
"editor.emmet.action.decrementNumberByOne",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": ":$CURRENT_MINUTE]"
}
}
]
}
]
for the emmet decrementNumberByOne
trick to work you can't have two numbers in the line only one of which you want to decremnt. That is why your actual snippet is divided in a half, with the minutes added after the decrement has taken place.
Now, assign your chosen keybinding to this macro, in keybindings.json:
{
"key": "ctrl+shift+i",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.decrementHourInSnippet" }
}
and it works. Demo:

Of course, as you said you don't care about going from 0
to -1
which is what I presume it would do after midnight for an hour.