macosvisual-studio-codeoperating-systemkey-bindings

Vscode : Define different keybindings depending on OS


I am developing an Extension for Vscode. For a particular command, I use a specific keybinding (ctrl + Up) that works fine on Linux and Windows but not in MacOs (used elsewhere) I would like to keep this keybinding for Linux and windows but define a different one for MacOs, I tried the when field in the `package.json file of my extension :

"key": "ctrl+alt+up",
"command": "mycommand",
"when": "os:mac"

But it does not work.

Any idea?


Solution

  • Use the platform context keys, isLinux, isMac, and isWindows. You can write when clauses like (isLinux || isWindows) && (...), or isMac && (...), or !isMac && (...)