What is codemirror?
CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code and comes with a number of language modes and addons that implement more advanced editing functionality. A rich programming API and a CSS theming system are available for customizing CodeMirror to fit the needs of the project.
What are codemirror's main functionalities?
Syntax highlighting
This feature allows for syntax highlighting of code written in various programming languages. The example code initializes a CodeMirror instance with JavaScript syntax highlighting.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'javascript'});
Code editing
CodeMirror provides a rich text editor for code, with features like auto-indentation, line numbers, and bracket matching. The example code creates an editor instance with some JavaScript code pre-filled.
var editor = CodeMirror(document.body, {value: 'function myScript(){return 100;}', mode: 'javascript'});
Autocompletion
Autocompletion can be enabled to suggest completions for the current token. The example code sets up an event listener to trigger autocompletion on certain inputs.
editor.on('inputRead', function onChange(editor, input) { if (input.text[0] === ';' || input.text[0] === ' ') { return; } CodeMirror.commands.autocomplete(editor); });
Themes
CodeMirror supports various themes to customize the appearance of the editor. The example code initializes a CodeMirror instance with the Monokai theme.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'javascript', theme: 'monokai'});
Addons
CodeMirror has a variety of addons that can extend its functionality, such as displaying line numbers or matching brackets. The example code enables line numbers and bracket matching for the editor.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'javascript', lineNumbers: true, matchBrackets: true});
Other packages similar to codemirror
ace
Ace is a standalone code editor written in JavaScript. It matches many of the features of CodeMirror, such as syntax highlighting, themes, and extensions. However, Ace is known for its performance and is used in large-scale applications like Cloud9 IDE.
monaco-editor
Monaco Editor is the code editor that powers VS Code, which is known for its rich IntelliSense, integrated debugging, and embedded Git control. It's more feature-rich compared to CodeMirror and is designed to work well in any browser.
brace
Brace is a fork of Ace that is browserify compatible. It has a similar feature set to Ace and by extension, CodeMirror, but it is designed to be easier to install and use with browserify.
CodeMirror
CodeMirror is a versatile text editor implemented in JavaScript for
the browser. It is specialized for editing code, and comes with over
100 language modes and various addons that implement more advanced
editing functionality. Every language comes with fully-featured code
and syntax highlighting to help with reading and editing complex code.
A rich programming API and a CSS theming system are available for
customizing CodeMirror to fit your application, and extending it with
new functionality.
You can find more information (and the
manual) on the project
page. For questions and discussion, use the
discussion forum.
See
CONTRIBUTING.md
for contributing guidelines.
The CodeMirror community aims to be welcoming to everybody. We use the
Contributor Covenant
(1.1) as our code of
conduct.
Installation
Either get the zip file with
the latest version, or make sure you have Node
installed and run:
npm install codemirror
NOTE: This is the source repository for the library, and not the
distribution channel. Cloning it is not the recommended way to install
the library, and will in fact not work unless you also run the build
step.
Quickstart
To build the project, make sure you have Node.js installed (at least version 6)
and then npm install
. To run, just open index.html
in your
browser (you don't need to run a webserver). Run the tests with npm test
.