Keybinding: {
    command:
        | Selector
        | string[]
        | [string, any]
        | [string, any, any]
        | [string, any, any, any];
    ifLayout?: string[];
    ifMode?: ParseMode;
    ifPlatform?:
        | "macos"
        | "!macos"
        | "windows"
        | "!windows"
        | "linux"
        | "!linux"
        | "ios"
        | "!ios"
        | "android"
        | "!android"
        | "chromeos"
        | "!chromeos";
    key: string;
}

A keybinding associates a combination of physical keyboard keys with a command.

For example:

{
"key": "cmd+a",
"command": "selectAll",
},
{
"key": 'ctrl+[Digit2]',
"ifMode": 'math',
"command": ['insert', '\\sqrt{#0}'],
}

Type declaration

  • command:
        | Selector
        | string[]
        | [string, any]
        | [string, any, any]
        | [string, any, any, any]

    The command is a single selector, or a selector with arguments

  • OptionalifLayout?: string[]
  • OptionalifMode?: ParseMode

    If specified, this indicates in which mode this keybinding will apply. If none is specified, the keybinding will apply in every mode.

  • OptionalifPlatform?:
        | "macos"
        | "!macos"
        | "windows"
        | "!windows"
        | "linux"
        | "!linux"
        | "ios"
        | "!ios"
        | "android"
        | "!android"
        | "chromeos"
        | "!chromeos"

    If specified, this indicates the OS platform to which this keybinding apply.

    For example, if set to !macos this key binding will apply to every platform, except macOS.

  • key: string

    The pressed keys that will trigger this keybinding.

    The key is made up of modifiers and the key itself.

    The following modifiers can be used:

    Platform Modifiers
    macOS, iOS ctrl, shift, alt, cmd
    Windows ctrl, shift, alt, win
    Linux, Android, ChromeOS ctrl, shift, alt, meta

    If the cmd modifier is used, the keybinding will only apply on macOS. If the win modifier is used, the keybinding will only apply to Windows. If the meta modifier is used, the keybinding will apply to platforms other than macOS or Windows.

    The alt key is the option key on Apple keyboards.

    The following values for keys can be used:

    • az, 09
    • `, -, =, [, ], \, ;, ', ,, ., /
    • left, up, right, down, pageup, pagedown, end, home
    • tab, enter, escape, space, backspace, delete
    • f1f19
    • pausebreak, capslock, insert
    • numpad0numpad9, numpad_multiply, numpad_add, numpad_separator
    • numpad_subtract, numpad_decimal, numpad_divide

    The values will be remapped based on the current keyboard layout. So, for example if a is used, on a French AZERTY keyboard the keybinding will be associated with the key labeled 'A' (event though it corresponds to the key labeled 'Q' on a US QWERTY keyboard).

    To associate keybindings with physical keys independent of the keyboard layout, use the following keycodes:

    • [KeyA][KeyZ], [Digit0][Digit9]
    • [Backquote], [Minus], [Equal], [BracketLeft], [BracketRight], [Backslash], [Semicolon], [Quote], [Comma], [Period], [Slash]
    • [ArrowLeft], [ArrowUp], [ArrowRight], [ArrowDown], [PageUp], [PageDown], [End], [Home]
    • [Tab], [Enter], [Escape], [Space], [Backspace], [Delete]
    • [F1][F19]
    • [Pause], [CapsLock], [Insert]
    • [Numpad0][Numpad9], [NumpadMultiply], [NumpadAdd], [NumpadComma]
    • [NumpadSubtract], [NumpadDecimal], [NumpadDivide]

    For example, using [KeyQ] will map to the the key labeled 'Q' on a QWERTY keyboard, and to the key labeled 'A' on an AZERTY keyboard.

    As a general guideline, it is preferable to use the key values az for keybinding that are pseudo-mnemotechnic. For the other, it is generally preferable to use the keycodes.

    Consider the key combination: alt+2. With an AZERTY (French) layout, the digits (i.e. '2') are only accessible when shifted. The '2' key produces 'é' when not shifted. It is therefore impossible on an AZERTY keyboard to produce the alt+2 key combination, at best it would be alt+shift+2. To indicate that the intended key combination should be alt and the key on the keyboard which has the position of the 2 key on a US keyboard, a key code should be used instead: alt+[Digit2]. This will correspond to a key combination that can be generated on any keyboard.