Custom Keybinds - slugcat-dev/mark-ed GitHub Wiki

The keymap object defines custom keybinds, where each keybind is mapped to a handler. The property name defines the key combination, and the value is the function that will be executed when that key combination is pressed.

Key modifiers:

  • Ctrl
  • Shift
  • Alt
  • Meta
  • CtrlMeta (Ctrl on Windows and Linux, Meta on MacOS)
  • CtrlAlt (Ctrl on Windows and Linux, Alt on MacOS)

Most keybinds work like this: First modify the content, then adjust the selection to the new content. The following code adds a keybind for basic bold formatting. A more complete version would also wrap selected text with asterisks instead of replacing it.

keymap: {
  'CtrlMeta B': editor => {
    // Insert bold formatting
    editor.insertAtSelection('**bold**')

    // Select the word "bold"
    editor.setSelection({
      start: editor.selection.start - 6,
      end: editor.selection.start - 2
    })
  }
}