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.
Using
fallthrough: ['default']
Works better for me as it includes macros such as ctrl+a for select all.