CodeMirror
Home Manual Code
Any Word Completion
Any Word Completion Demo
(function() { "use strict";
var WORD = /[\w$]+/g, RANGE = 500;
CodeMirror.registerHelper("hint", "anyword", function(editor, options) { var word = options && options.word || WORD; var range = options && options.range || RANGE; var cur = editor.getCursor(), curLine = editor.getLine(cur.line); var start = cur.ch, end = start; while (end
Press ctrl-space to activate autocompletion. The completion uses the anyword-hint.js module, which simply looks at nearby words in the buffer and completes to those.
CodeMirror.commands.autocomplete = function(cm) { cm.showHint({hint: CodeMirror.hint.anyword}); } var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, extraKeys: {"Ctrl-Space": "autocomplete"} });