@codemirror/search

Find, replace, regex search, and match highlighting for the CodeMirror 6 code editor.

Library
npm
v6.7.2
26 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
25 /100 Needs Attention
Development Activity 8
Maintenance 0
Community 20
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 88
Code Quality 85
Innovation 88
Learning Curve 58

@codemirror/search is the official search extension for CodeMirror 6, the extensible in-browser code editor. It adds an interactive search-and-replace panel, plain-string and regular-expression matching, whole-word and case-sensitive options, and live highlighting of the current selection’s occurrences across the document.

Beyond the ready-made panel, the package exposes composable editor commands and two standalone match-iterator classes — SearchCursor and RegExpCursor — that you can drive directly from your own UI or keymaps. It follows CodeMirror’s facet-and-extension model, so search state integrates cleanly with the rest of your editor configuration.

What You Get

  • A drop-in search panel with find, replace, replace-all, case-sensitivity, whole-word, and regular-expression toggles
  • A ready-made searchKeymap plus individual commands (findNext, findPrevious, replaceNext, replaceAll, openSearchPanel, gotoLine) you can bind however you like
  • SearchCursor and RegExpCursor iterator classes for scanning document text by string or regex, usable independently of the panel
  • Live selection-match highlighting via highlightSelectionMatches and multi-cursor selectNextOccurrence
  • An immutable SearchQuery value object and facet-based configuration for panel placement and default match options

Common Use Cases

  • Adding Ctrl/Cmd-F find-and-replace to a CodeMirror-based code or text editor in a web app
  • Building a bespoke search UI while reusing the underlying cursors and commands
  • Highlighting every occurrence of the current selection as the user moves through a document
  • Implementing editor-style ‘select next occurrence’ multi-cursor editing

Under The Hood

Architecture The entry point src/search.ts exposes search(config?), which returns a CodeMirror Extension combining a searchConfigFacet with the core search extensions. Search state lives in a StateField mutated through StateEffects such as setSearchQuery, while editor Commands (findNext, findPrevious, replaceNext, replaceAll, openSearchPanel, closeSearchPanel) act on the EditorView/EditorState. The UI is a CodeMirror Panel shown via showPanel and assembled with the tiny crelt DOM helper. Text matching is cleanly separated into two iterator classes: SearchCursor (src/cursor.ts) performs buffered, NFKD-normalized plain-string scanning over a TextIterator, and RegExpCursor (src/regexp.ts) does line-oriented regular-expression matching. src/selection-match.ts supplies highlightSelectionMatches as a ViewPlugin that emits a DecorationSet, and src/goto-line.ts adds the go-to-line command. The result is a well-layered design: pure iterators feed a SearchQuery model, which drives state and commands, which the view renders.

Tech Stack The package is written entirely in TypeScript and depends only on @codemirror/state (^6), @codemirror/view (^6.37), and crelt (^1) for DOM construction. It is ESM-first but ships dual builds (dist/index.js and dist/index.cjs) with bundled type declarations and sideEffects: false for tree-shaking. Builds run through @codemirror/buildhelper (cm-buildhelper) and tests through cm-runtests, keeping the dependency and tooling surface deliberately minimal.

Code Quality The test/ directory covers the core primitives — test-cursor.ts, test-query.ts, and test-selection-match.ts — exercising string/regex matching, query parsing, and selection highlighting. Source files are small and focused, use strict TypeScript with readonly fields and explicit iterator interfaces, and carry /// doc comments on every public API that generate the reference docs. Regex validity is guarded via validRegExp. Test coverage concentrates on the matching engine rather than the panel/command UI.

API Design Developer experience is excellent within the CodeMirror ecosystem: a single search(config?) extension is the entry point, configured through a typed SearchConfig (panel placement, default case-sensitivity, literal, whole-word, regexp, custom createPanel, and scrollToMatch). Commands are exported individually so they compose into custom keymaps, SearchQuery is an immutable value object, and the SearchCursor/RegExpCursor classes are usable standalone outside the editor. Naming is consistent with CodeMirror 6 conventions; the main cost is the boilerplate required to author a fully custom panel.

Used by 35 apps in this directory

TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

33,179

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
85
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
Vue
43%
MIT

Alexandrie

Collaboration · Knowledge Management · Note Taking

2,777

The open-source, offline-first Notion, Obsidian & Confluence alternative with multi-tenant teams, OIDC/SSO, and one-command Docker deployment.

View details
86
Repo Health
73
Technical
74
Dependency
Built with
Vue 43%
TypeScript 41%
Go 13%
Updated 1 weeks ago
TypeScript
98%
Other

Dokploy

Devops · Hosting Control Panel · Security

37,543

Self-hosted PaaS that deploys apps and databases on your own VPS using Docker, Traefik, and multi-build-system orchestration

View details
88
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,441

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
59
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 1 months ago
TypeScript
64%
Other

Epicenter

Developer Tools · Knowledge Management · Note Taking

4,808

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
64
Dependency
Built with
TypeScript 64%
HTML 13%
Svelte 13%
Updated 5 days ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,962

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
90
Repo Health
79
Technical
64
Dependency
Built with
TypeScript 82%
Svelte 17%
Updated 1 weeks ago
Go
74%
Other

Flipt

Developer Tools · Devops

4,911

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
69
Dependency
Built with
Go 74%
TypeScript 25%
Updated 4 days ago
TypeScript
51%
MIT

Ghost

Blogging · CMS

55,450

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
67
Dependency
Built with
TypeScript 51%
JavaScript 44%
Updated 4 days ago
Go
83%
MIT

Gitea

Developer Tools · Devops · Project Management

58,194

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
64
Dependency
Built with
Go 83%
Updated 4 days ago

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