CodeMirror

# { } CodeMirror

    /* In-browser code editing
       made bearable */

CodeMirror is a JavaScript component that provides a code editor in the browser. When a mode is available for the language you are coding in, it will color your code, and optionally help with indentation.

A rich programming API and a CSS theming system are available for customizing CodeMirror to fit your application, and extending it with new functionality.

## Supported modes:

- C, C++, C#
- Clojure
- CoffeeScript
- Common Lisp
- CSS
- diff
- ECL
- Erlang
- Go
- Groovy
- Haskell
- Haxe
- HTML embedded scripts
- HTML mixed-mode
- Java
- JavaScript
- Jinja2
- LESS
- Lua
- Markdown (Github-flavour)
- MySQL
- NTriples
- OCaml
- Pascal
- Perl
- PHP
- Pig Latin
- PL/SQL
- Properties files
- Python
- R
- RPM spec and changelog
- reStructuredText
- Ruby
- Rust
- Scala
- Scheme
- Shell
- Sieve
- Smalltalk
- Smarty
- SPARQL
- sTeX, LaTeX
- Tiddlywiki
- Tiki wiki
- VB.NET
- VBScript
- Velocity
- Verilog
- XML/HTML
- XQuery
- YAML

## Usage demos:

- Autocompletion (XML)
- Search/replace
- Code folding
- Mode overlays
- Mode multiplexer
- HTML editor with preview
- Auto-resizing editor
- Setting breakpoints
- Highlighting the current line
- Highlighting selection matches
- Theming
- Stand-alone highlighting
- Full-screen editing
- Mode auto-changing
- Visible tabs
- Autoformatting of code
- Emacs keybindings
- Vim keybindings
- Automatic xml tag closing
- Lazy mode loading

## Real-world uses:

- jsbin.com (JS playground)
- Light Table (experimental IDE)
- Adobe Brackets (code editor)
- Mergely (interactive diffing)
- Google Apps Script
- GitHub's Android app
- Eloquent JavaScript (book)
- Zen Coding (fast XML editing)
- Paper.js (graphics scripting)
- Go language tour
- Codev (collaborative IDE)
- Tributary (augmented editing)
- Prose.io (github content editor)
- WeScheme (learning tool)
- WebGL playground
- ql.io (http API query helper)
- Elm language examples
- The File Tree (collab editor)
- BlueGriffon (HTML editor)
- JSHint (JS linter)
- kl1p (paste service)
- SQLFiddle (SQL playground)
- Try Haxe (Haxe Playground)
- CSSDeck (CSS showcase)
- CKWNC (UML editor)
- sketchPatch Livecodelab
- NoTex (rST authoring)

## Getting the code

All of CodeMirror is released under a MIT-style license. To get it, you can download the latest release or the current development snapshot as zip files. To create a custom minified script file, you can use the compression API.

We use git for version control. The main repository can be fetched in this way:

    git clone http://marijnhaverbeke.nl/git/codemirror

CodeMirror can also be found on GitHub at marijnh/CodeMirror. If you plan to hack on the code and contribute patches, the best way to do it is to create a GitHub fork, and send pull requests.

## Documentation

The manual is your first stop for learning how to use this library. It starts with a quick explanation of how to use the editor, and then describes the API in detail.

For those who want to learn more about the code, there is an overview of the internals available. The source code itself is, for the most part, also well commented.

## Support and bug reports

Community discussion, questions, and informal bug reporting is done on the CodeMirror Google group. There is a separate group, CodeMirror-announce, which is lower-volume, and is only used for major announcements—new versions and such. These will be cross-posted to both groups, so you don't need to subscribe to both.

Though bug reports through e-mail are responded to, the preferred way to report bugs is to use the Github issue tracker. Before reporting a bug, read these pointers. Also, the issue tracker is for bugs, not requests for help.

When none of these seem fitting, you can simply e-mail the maintainer directly.

## Supported browsers

The following desktop browsers are able to run CodeMirror:

- Firefox 2 or higher
- Chrome, any version
- Safari 3 or higher
- Opera 9 or higher (with some key-handling problems on OS X)
- Internet Explorer 7 or higher in standards mode
  (So not quirks mode. But quasi-standards mode with a transitional doctype is also flaky. `<!doctype html>` is recommended.)

I am not actively testing against every new browser release, and vendors have a habit of introducing bugs all the time, so I am relying on the community to tell me when something breaks. See here for information on how to contact me.

Mobile browsers mostly kind of work, but, because of limitations and their fundamentally different UI assumptions, show a lot of quirks that are hard to work around.

## Commercial support

CodeMirror is developed and maintained by me, Marijn Haverbeke, in my own time. If your company is getting value out of CodeMirror, please consider purchasing a support contract.

- You'll be funding further work on CodeMirror.
- You ensure that you get a quick response when you have a problem, even when I am otherwise busy.

CodeMirror support contracts exist in two forms—basic at €100 per month, and premium at €500 per month. Contact me for further information.

Download the latest release

## Support CodeMirror

- Donate (Paypal or bank)
- Purchase commercial support

Bank: Rabobank
Country: Netherlands
SWIFT: RABONL2U
Account: 147850770
Name: Marijn Haverbeke
IBAN: NL26 RABO 0147 8507 70

## Reading material

- User manual
- Browse the code

## Releases

19-09-2012: Version 2.34:

- New mode: Common Lisp.
- Fix right-click select-all on most browsers.
- Change the way highlighting happens:
  Saves memory and CPU cycles.
  `compareStates` is no longer needed.
  `onHighlightComplete` no longer works.
- Integrate mode (Markdown, XQuery, CSS, sTex) tests in central testsuite.
- Add a `CodeMirror.version` property.
- More robust handling of nested modes in formatting and closetag plug-ins.
- Un/redo now preserves marked text and bookmarks.
- Full list of patches.

19-09-2012: Version 3.0, beta 1:

BETA release, new major version. Only partially backwards-compatible. See the upgrading guide for more information. Major new features are:

- Bi-directional text support.
- More powerful gutter model.
- Support for arbitrary text/widget height.
- In-line widgets.
- Generalized event handling.

23-08-2012: Version 2.33:

- New mode: Sieve.
- New `getViewPort` and `onViewportChange` API.
- Configurable cursor blink rate.
- Make binding a key to `false` disabling handling (again).
- Show non-printing characters as red dots.
- More tweaks to the scrolling model.
- Expanded testsuite. Basic linter added.
- Remove most uses of `innerHTML`. Remove `CodeMirror.htmlEscape`.
- Full list of patches.

23-07-2012: Version 2.32:

Emergency fix for a bug where an editor with line wrapping on IE will break when there is no scrollbar.

20-07-2012: Version 2.31:

- New modes: OCaml, Haxe, and VB.NET.
- Several fixes to the new scrolling model.
- Add a `setSize` method for programmatic resizing.
- Add `getHistory` and `setHistory` methods.
- Allow custom line separator string in `getValue` and `getRange`.
- Support double- and triple-click drag, double-clicking whitespace.
- And more... (all patches)

22-06-2012: Version 2.3:

- New scrollbar implementation. Should flicker less. Changes DOM structure of the editor.
- New theme: vibrant-ink.
- Many extensions to the VIM keymap (including text objects).
- Add mode-multiplexing utility script.
- Fix bug where right-click paste works in read-only mode.
- Add a `getScrollInfo` method.
- Lots of other fixes.

23-05-2012: Version 2.25:

- New mode: Erlang.
- Remove xmlpure mode (use xml.js).
- Fix line-wrapping in Opera.
- Fix X Windows middle-click paste in Chrome.
- Fix bug that broke pasting of huge documents.
- Fix backspace and tab key repeat in Opera.

23-04-2012: Version 2.24:

- Drop support for Internet Explorer 6.
- New modes: Shell, Tiki wiki, Pig Latin.
- New themes: Ambiance, Blackboard.
- More control over drag/drop with `dragDrop` and `onDragEvent` options.
- Make HTML mode a bit less pedantic.
- Add `compoundChange` API method.
- Several fixes in undo history and line hiding.
- Remove (broken) support for `catchall` in key maps, add `nofallthrough` boolean field instead.

26-03-2012: Version 2.23:

- Change default binding for tab [more]
  Starting in 2.23, these bindings are default:
  - Tab: Insert tab character
  - Shift-tab: Reset line indentation to default
  - Ctrl/Cmd-[: Reduce line indentation (old tab behaviour)
  - Ctrl/Cmd-]: Increase line indentation (old shift-tab behaviour)
- New modes: XQuery and VBScript.
- Two new themes: lesser-dark and xq-dark.
- Differentiate between background and text styles in `setLineClass`.
- Fix drag-and-drop in IE9+.
- Extend `charCoords` and `cursorCoords` with a `mode` argument.
- Add `autofocus` option.
- Add `findMarksAt` method.

27-02-2012: Version 2.22:

- Allow key handlers to pass up events, allow binding characters.
- Add `autoClearEmptyLines` option.
- Properly use tab stops when rendering tabs.
- Make PHP mode more robust.
- Support indentation blocks in code folder.
- Add a script for highlighting instances of the selection.
- New .properties mode.
- Fix many bugs.

27-01-2012: Version 2.21:

- Added LESS, MySQL, Go, and Verilog modes.
- Add `smartIndent` option.
- Support a cursor in `readOnly`-mode.
- Support assigning multiple styles to a token.
- Use a new approach to drawing the selection.
- Add `scrollTo` method.
- Allow undo/redo events to span non-adjacent lines.
- Lots and lots of bugfixes.

20-12-2011: Version 2.2:

- Slightly incompatible API changes. Read this.
- New approach to binding keys, support for custom bindings.
- Support for overwrite (insert).
- Custom-width and stylable tabs.
- Moved more code into add-on scripts.
- Support for sane vertical cursor movement in wrapped lines.
- More reliable handling of editing marked text.
- Add minimal emacs and vim bindings.
- Rename `coordsFromIndex` to `posFromIndex`, add `indexFromPos` method.

Older releases...