Function Signature
Parameters
The CodeMirror 6 EditorView instance from which to retrieve the CM5 adapter.
Returns
Returns the CodeMirror 5 compatibility adapter if the Vim extension is active, or
null if the view doesn’t have the Vim extension enabled.Description
ThegetCM() function provides access to the CodeMirror 5 compatibility layer that powers the Vim extension. This adapter allows you to use the familiar CM5 Vim API from CodeMirror 5 with CodeMirror 6 editors.
The returned CodeMirror object provides the same API that was available in CodeMirror 5’s Vim extension, enabling you to:
- Execute Vim commands programmatically
- Configure Vim settings
- Define custom Ex commands
- Map and unmap keys
- Access the Vim state
Usage
When to Use
UsegetCM() when you need to:
- Migrate from CM5: Port existing CM5 Vim configuration code to CM6
- Programmatic Control: Execute Vim commands or change modes programmatically
- Custom Configuration: Define custom Ex commands, operators, or key mappings
- Access Vim State: Read or modify the internal Vim state
Important Notes
The CodeMirror 5 API returned by
getCM() is a compatibility layer. While it provides the same interface as CM5, it operates on a CM6 editor under the hood.Example: Complete Integration
See Also
- vim() - Create the Vim extension
- Vim object - Configure Vim behavior
- CodeMirror 5 Vim API - Original CM5 documentation

