Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To change the default keyboard shortcuts in Ace Editor, follow these steps:

  1. Create a new Ace Editor instance by calling the ace.edit function on your HTML element.
var editor = ace.edit("editor");
  1. Access the commands property of the editor instance to get a list of available commands.
var commands = editor.commands;
  1. Use the bindKey method of the commands object to set a new keyboard shortcut for a specific command. The bindKey method takes two arguments: a keyboard shortcut string and a command object.
commands.bindKey("Ctrl-S", function() {
    // save the document
});
  1. You can also use the addCommand method to create a new command and assign it a keyboard shortcut.
var saveCommand = {
    name: "save",
    bindKey: {win: "Ctrl-S", mac: "Command-S"},
    exec: function() {
        // save the document
    }
};

commands.addCommand(saveCommand);

Note that you can specify different keyboard shortcuts for Windows and Mac by using the win and mac properties in the bindKey object.