@codemirror/commands

A collection of editing, selection, deletion, indentation, and undo-history commands with default keymaps for the CodeMirror 6 code editor.

Library
npm
v6.11.0
39stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
27/100Needs Attention
Development Activity12
Maintenance0
Community24
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture82
Code Quality74
Innovation70
Learning Curve68

@codemirror/commands supplies the editing behavior that most code editors need but @codemirror/view and @codemirror/state deliberately leave out: cursor and selection movement (by character, group, subword, line, page, syntax node, or document boundary), deletion, line manipulation, indentation, character transposition, and an undo/redo history extension. Each behavior is exposed as a plain Command or StateCommand function plus pre-built KeyBinding arrays (standardKeymap, defaultKeymap, emacsStyleKeymap, historyKeymap), so an application wires up editing behavior by spreading a keymap into @codemirror/view’s keymap facet rather than reimplementing cursor and selection logic from scratch.

Because every command is just a function of {state, dispatch} or an EditorView, they compose cleanly with custom key bindings, can be called programmatically outside of a keypress, and interoperate with @codemirror/language for syntax-aware operations like toggleComment, indentSelection, and cursorSyntaxLeft/cursorSyntaxRight. The package is a peer dependency of nearly every CodeMirror 6 setup (including presets like codemirror and basic-setup) and receives frequent point releases fixing selection-association and cursor-placement edge cases.

What You Get

  • Cursor and selection commands for character, group, subword, line, page, syntax-node, and document-boundary motion, each with a select* counterpart for extending the selection
  • Deletion commands (deleteCharBackward, deleteGroupForward, deleteLine, deleteTrailingWhitespace, etc.) covering per-character, per-group, and per-line removal in both directions
  • Line manipulation and indentation commands: moveLineUp/moveLineDown, copyLineUp/copyLineDown, indentMore/indentLess, indentSelection, and Tab handling via insertTab/indentWithTab
  • An undo/redo history() extension with undo, redo, undoSelection, redoSelection, configurable grouping (newGroupDelay), and invertedEffects for making custom StateEffects undoable
  • Line and block commenting/uncommenting (toggleComment, toggleLineComment, toggleBlockComment) driven by language-provided CommentTokens
  • Pre-built keymaps — standardKeymap, defaultKeymap (superset with syntax-aware and Alt/Cmd bindings), emacsStyleKeymap, and historyKeymap — ready to spread into keymap.of([...])

Common Use Cases

  • Wiring baseline editing behavior (arrow keys, backspace, select-all, undo/redo) into a from-scratch CodeMirror 6 editor via defaultKeymap
  • Adding syntax-aware operations such as commenting a selection or expanding the selection to the enclosing syntax node in a code-editing product
  • Building a custom keymap (e.g. Emacs- or Vim-flavored bindings) by picking individual command functions like cursorGroupLeft or deleteToLineEnd rather than using the packaged keymaps
  • Adding an undo history to an embedded config/query/formula editor and exposing undo/redo as toolbar buttons that call the exported undo/redo commands directly

Under The Hood

Architecture — The package is organized around three files with a clean dependency direction: commands.ts (1,124 lines) defines pure selection/deletion/indentation commands as Command/StateCommand functions built from small composable helpers (moveSel, deleteBy, extendSel) that transform an EditorState’s EditorSelection and dispatch a Transaction; history.ts (399 lines) implements undo/redo as a StateField (historyField_) storing done/undone branches of HistEvents, using transaction annotations (fromHistory, isolateHistory) to distinguish history-replay transactions from normal edits and a time/newGroupDelay-based heuristic to merge adjacent keystrokes into one undo step; comment.ts (201 lines) implements line/block toggling by reading language-provided CommentTokens and computing per-line or per-range comment insertion/removal as a single ChangeSet. commands.ts re-exports both sibling modules so the whole package presents one flat public surface, and standardKeymap/defaultKeymap are assembled at the bottom of commands.ts by concatenating arrays of KeyBinding objects that reference the exported command functions.

Tech Stack — Pure TypeScript (100% of the codebase, 134KB) with @codemirror/state (^6.6.0), @codemirror/view (^6.27.0), @codemirror/language (^6.0.0), and @lezer/common (^1.1.0) as direct dependencies — it sits strictly above state/view and below any language-specific package. Build tooling is CodeMirror’s own @codemirror/buildhelper (cm-buildhelper src/commands.ts) producing dual ESM/CJS output (dist/index.js / dist/index.cjs) with bundled .d.ts types; package.json declares "type": "module" and "sideEffects": false for tree-shaking. Tests run via cm-runtests (the shared CodeMirror test runner, cm-buildhelper’s sibling).

Code Quality — Tests total 1,452 lines across four files (test-commands.ts 259, test-comment.ts 221, test-history.ts 646, webtest-commands.ts 292 for DOM-dependent cases), giving the undo history — the most stateful, edge-case-prone part of the package — by far the heaviest coverage. Every exported command in commands.ts and history.ts carries a ///-prefixed doc comment consumed by CodeMirror’s own doc generator, and internal helpers are small, single-purpose functions (moveSel, rangeEnd, deleteBy) rather than large branching functions, keeping each command’s diff-sized and independently testable. No linter config ships in the repo; consistency is enforced by the shared CodeMirror build tooling and code review norms across the monorepo-like family of packages.

API Design — The public surface is deliberately flat and uniform: nearly every export is either a Command/StateCommand function with the exact signature (target) => boolean, or a readonly KeyBinding[] array, so consumers can mix hand-picked commands and packaged keymaps without adapters. The select* naming convention (mirroring every cursor* command with a same-named select* variant) makes the API’s shape predictable without reading docs. The tradeoff is a large flat namespace — over 60 command exports — with no sub-grouping, so discoverability leans on the README’s categorized command list (Selection / Deletion / Line manipulation / Indentation / Undo History / Commenting) rather than the module structure itself.

Used by 52 apps in this directory

TypeScript
99%
Other

Activepieces

Automation · AI Assistants

23,887

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

32,102

Free, open-source Cowork desktop app that unifies Claude Code, Codex, Gemini CLI, and 20+ AI agents into a single platform with multi-agent teams, 24/7 cron automation, and zero-config built-in agent.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript95%
Updated today
TypeScript
69%
Other

Budibase

Low Code Platforms · No Code Platforms

28,220

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
92
Repo Health
81
Technical
63
Dependency
Built with
TypeScript69%
Svelte26%
Updated today
Ruby
62%
GPL 2.0

Discourse

Community

47,672

Open-source community platform with dynamic trust levels, real-time chat, and a powerful plugin architecture for self-hosted forums.

View details
89
Repo Health
89
Technical
67
Dependency
Built with
Ruby62%
JavaScript31%
Updated today
Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,437

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
70
Repo Health
90
Technical
62
Dependency
Built with
Java34%
TypeScript27%
Scala26%
Updated 1 weeks ago
TypeScript
72%
Other

Epicenter

Knowledge Management · Note Taking · Developer Tools

4,761

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
88
Repo Health
90
Technical
68
Dependency
Built with
TypeScript72%
Svelte15%
Updated today
JavaScript
52%
MIT

evidence

Analytics · Data Engineering

6,861

Turn SQL queries and markdown files into polished, interactive data apps and business intelligence reports — no drag-and-drop, no GUI, just code.

View details
65
Repo Health
79
Technical
65
Dependency
Built with
JavaScript52%
Svelte40%
Updated today
Python
64%
MIT

Flowfile

Data Engineering

341

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python64%
Vue19%
TypeScript16%
Updated today
JavaScript
51%
MIT

Ghost

CMS · Blogging

54,795

Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.

View details
96
Repo Health
85
Technical
69
Dependency
Built with
JavaScript51%
TypeScript43%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search