How to dynamically switch modes with CodeMirror?

Shamoon picture Shamoon · May 25, 2011 · Viewed 8.9k times · Source

How to dynamically switch modes with CodeMirror?

I have the default set, but need to switch it.

Answer

Ponmudi VN picture Ponmudi VN · Jun 26, 2014

Something like this would help you.

First, set CodeMirror:

this.editor = CodeMirror.fromTextArea(document.getElementById("textAreaCodeMirror"), {
    lineNumbers: true,
    matchBrackets: true,
    styleActiveLine: true,
    theme:"eclipse",
    mode:language
});

Then, to change the mode

this.editor.setOption("mode", language);