vue-codemirror is a Vue 3 component that provides a robust wrapper for CodeMirror 6, the modern code editor library. The current stable version is 6.1.1. This library is actively maintained, with frequent minor releases and bug fixes, indicated by its release history. A key differentiator is its strict adherence to Vue 3 and CodeMirror 6, making it completely incompatible with previous versions of CodeMirror (v5 and below) or Vue (v2). It leverages CodeMirror 6's native ES Module structure, meaning it no longer supports UMD modules for direct browser references, requiring a module bundler. Users must explicitly install additional CodeMirror language, theme, and state packages as needed, as they are not bundled.
npm install vue-codemirrorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic setup of the CodeMirror 6 editor component in a Vue 3 application, including v-model binding, applying language extensions and themes, and handling editor events like 'ready', 'change', 'focus', and 'blur'.
For new projects, use vue-codemirror@6.x. For existing Vue 2 / CodeMirror 5 projects, you must remain on vue-codemirror@4.x or undertake a full migration to Vue 3 and CodeMirror 6.
Ensure your project is set up with a modern JavaScript module bundler that supports ES Modules. Avoid attempting to include the library via a <script> tag directly in HTML.
Install required CodeMirror packages using `npm install @codemirror/lang-html @codemirror/theme-one-dark` and import them in your Vue component as extensions.
Add the specific `@codemirror/*` package to your `package.json`'s `dependencies` section, for instance: `"@codemirror/state": "6.x"`.
Ensure you have `import { Codemirror } from 'vue-codemirror'` and registered it in your component's `components` option: `components: { Codemirror }`.Run `npm install codemirror` or `yarn add codemirror` to install the core CodeMirror library.
Update your import statements to use ES Module `import` syntax: `import { Codemirror } from 'vue-codemirror'`.Verify that all CodeMirror language, theme, and utility packages (e.g., `@codemirror/lang-javascript`) are installed, correctly imported, and properly added to the `extensions` array, e.g., `[javascript()]`.