key-bindingsace-editor

Setting keyboard bindings in ace editor


I am trying to figure out how to set keyboard bindings in ace editor to vscode key bindings. I can see in the CDN that there is a vscode keybinding file available I just don't know how to set it.

I have tried:

editor.setKeyboardHandler("ace/keybinding/vscode");

And not surprisingly it did not work. I searched through docs to see if I can find anything and I have exhausted my search options. Please help!


Solution

  • the correct id is "ace/keyboard/vscode", see the following snippet:

    <script src="https://cdn.jsdelivr.net/npm/ace-builds/src-noconflict/ace.js"></script>
    <script>
      var editor = ace.edit(null, {
        value: "test ctrl-D \n test",
        mode: "ace/mode/javascript"
      });
      editor.container.style.height = "100px";
      document.body.append(editor.container);
      editor.setKeyboardHandler("ace/keyboard/vscode");
    </script>