Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 30, 2013 19:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5680546 to your computer and use it in GitHub Desktop.
Save tmcw/5680546 to your computer and use it in GitHub Desktop.
CodeMirror keyMap Missing Documentation

An addendum to CodeMirror's keyMap documentation, which unfortunately glosses over the 'connecting the wires' section.

CodeMirror.keyMap.tabSpace = {
    Tab: function(cm) {
        var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
        cm.replaceSelection(spaces, "end", "+input");
    },
    fallthrough: ['basic']
};

var editor = CodeMirror.fromTextArea(code, {
    keyMap: 'tabSpace'
});

Like so:

  • keymaps are objects that are assigned to bits of CodeMirror.keyMap
  • Your keymap will usually have fallthrough: ['basic'] in it unless you want to reinvent the wheel.

That is all.

@skywickenden
Copy link

Using

fallthrough: ['default']

Works better for me as it includes macros such as ctrl+a for select all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment