Getting Started
Installation
Install the component together with codemirror:
Language support, linters, and themes are separate packages. Install the ones you need, for example:
Minimal example
This renders a plain editor without line numbers or key bindings. Add the basic prop to enable CodeMirror's basicSetup (line numbers, history, bracket matching, search, and more):
Use minimal instead of basic for minimalSetup. If both are set, basic takes precedence.
Adding a language
Pass a LanguageSupport object to the lang prop to enable syntax highlighting:
Global registration
The package exports an install function that registers the component as CodeMirror:
After that, <code-mirror> can be used in any template without importing it.
Package exports
Using from a CDN (jsDelivr)
vue-codemirror6 1.8.0 or later can be used without a bundler (Vue 3 only). Load the ESM files from jsDelivr through an import map, and register the component in your app:
CodeMirror stops working when two copies of @codemirror/state (or other @codemirror/* packages) are loaded, and Vue's reactivity breaks when two copies of Vue are loaded. Map every package to a single URL as above, and do not use jsDelivr's /+esm URLs: they pin dependency versions independently for each package, which easily leads to duplicates.
vue.esm-browser.prod.jsincludes the template compiler, so in-DOM templates like the one above work.- The last two entries of the import map are for
@codemirror/lang-javascript. Add the language packages you use, together with their@lezer/*parser packages, the same way. - To use the editor as a custom element without a Vue app, see Web Component.
Next steps
- Usage —
v-model, slots, read-only mode, and key bindings. - Languages, Linters & Themes