When I typed caret_sparks into NeNe Nib's project search, it went through 1,995 files, found 91 matching lines, and refreshed the list on each key I typed.
There's no index behind it, and no "wait 300 ms before searching" timer either. Here's the whole search side of the editor in about a minute:
What's in this post:
- One palette for files, tabs, settings and search
- What happens between a keystroke and the next list of hits
- What I chose not to build, and where that costs you
The editor
NeNe Nib is my text editor for Windows 11, written in C++23 on plain Win32 and Direct2D. It works like Notepad by default, and Ctrl+Shift+Space switches it to Vim editing. I've written about how fast it opens files and the caret motion in 1.2.0. This one is about finding things.
One palette, one key
Ctrl+P opens a single list. With an empty input it shows your open tabs, bookmarks, recently closed files and the files in the current folder, matched loosely by name. Type a few letters of a name and the file is there, with a preview on the right before you open it.
A mark at the start of the input narrows where the list comes from:
| Mark | Lists |
|---|---|
# | open tabs |
* | bookmarks |
@ | recently closed files |
/ | files in the current folder |
: | settings commands |
? | every operation, with its shortcut |
! | the whole project (the search in this post) |
% ^ & | symbols, diagnostics and references from a language server |
The language server marks only work when you connect one (clangd, for example). That's off by default.
One small thing I like: in :colorscheme, the theme under the selection previews its colors. Moving down the list of 125 themes repaints the editor as you go.
Search on every key
Ctrl+Shift+F (or :grep in Vim mode) opens the same palette with !. From then on, every change to the input starts a new search under the project root.
Here's what happens on one keystroke.
The UI thread only asks. It hands a request with a new ticket number to a port and returns at once. The port is this small:
class ProjectSearchPort { public: virtual void request(ProjectSearchRequest request) = 0; // a new request ends the previous one virtual void cancel(std::uint64_t ticket) = 0; [[nodiscard]] virtual std::vector<ProjectSearchBatch> collect() = 0; }; Threads and files stay behind it, in the Windows layer. The UI thread calls request, later collects whatever has arrived, and draws the rows that are visible.
A worker reads 1 MiB at a time. It walks the folder tree with FindFirstFileExW and reads each file in 1 MiB chunks. One unit of work is either one folder listing or one chunk, so a new request never waits behind a whole file.
Matching is a pure function. Each chunk goes to project_hits_in, which takes the bytes, the query and the state left by the previous chunk:
[[nodiscard]] ProjectChunkHits project_hits_in(const ProjectScan &scan, std::string_view chunk, const ProjectQuery &query, std::size_t room); A chunk can end in the middle of a line. That partial line is carried into the next chunk and matched as one line. A property test checks that cutting a file into chunks gives exactly the same hits as matching the whole file in one go.
Old work is thrown away. When you type the next character, the previous ticket is dropped. The worker finishes at most the chunk it's holding, and results with an old ticket are ignored. That's why there's no debounce timer: an outdated search costs one chunk, not one project.
How long is a chunk? On my machine, matching one 1 MiB chunk of source-like text took about 0.1 to 1.2 ms (Release build, median of 31 runs, measured once while other work was running on the PC). The design record has the numbers per query.
What it skips
To keep the search on your own files and away from surprises, the walk skips:
- hidden folders, and
.git,node_modules,buildandout - junctions and symbolic links to folders, so it can't loop
- files over 16 MiB, and files with a NUL byte in their first 8 KiB
- cloud files that aren't on the PC yet. Searching never triggers a download.
The query matches literally and ignores case, like Ctrl+F with ignorecase. Start it with / to use a Vim pattern instead. You get one hit per line, up to 1,000 hits, and Enter opens the file at that line and column.
What I didn't build
An external search tool. Running ripgrep as a child process would be fast, but I'd have to ship another executable with the editor. Reading the files myself on the worker was enough.
An index. An index would make huge trees fast, but it has to follow every change made outside the editor, and it needs somewhere to live. Without one, Nib reads the files every time. On a tree of a gigabyte, expect seconds, not milliseconds.
A delay before searching. Waiting 300 ms after the last key is the usual way to avoid wasted work. Dropping the old ticket does the same job, and the list doesn't lag behind your typing.
Where this costs you. The skip list is fixed (it doesn't read .gitignore yet), and lines that aren't valid UTF-8, such as Shift_JIS files, aren't matched. Both are on the list for later.
Takeaways
- Put the UI thread behind a tiny port, and give the work in small pieces to a worker.
- If a stale request only costs one small piece, you may not need a debounce at all.
- Make the matcher a pure function, and test that chunked results equal whole-file results.
Sources
- Design record: ADR 0167, project search on the worker (Japanese)
- The port:
ProjectSearchPort.hpp - The matcher:
ProjectHits.hpp - The palette marks and the preview: the README (FR-006, FR-026)
Try it
Get NeNe Nib on the Microsoft Store (free)
Open a project folder, press Ctrl+Shift+F, and type a name you use a lot. How large is the folder you usually search, and does your editor keep up with every key?



