Efficient Word Count
approvedby Blue Heron
Efficiently calculates and caches word counts for notes, with folder exclusion. Uses cache to avoid recalculating word counts for unchanged notes.
Efficient Word Count — Obsidian Plugin
This plugin efficiently calculates and caches the word counts of all Markdown files in your vault, excluding configurable folders like Templates. It updates in real-time as files change, and caches results to disk to speed up startup and vault-wide statistics.
Features
- Automatically builds a cache of word counts for all Markdown files.
- Excludes folders you specify (default:
Templates,.trash). - Listens to file create/modify/delete/rename events to update cache incrementally.
- Persists cache data on disk for fast startup.
- Exposes a global API (
window.wordCountCache) with:get(path)— word count for a specific file pathtotal()— total word count across all cached files
Installation
Available via the Community Plugins browser. If you want to install it manually:
- Clone or download this repository.
- Copy the plugin folder into your Obsidian vault’s
.obsidian/plugins/efficient-wordcount/. - Enable the plugin via Settings > Community Plugins.
- Wait a few seconds on vault load for the cache to build.
Usage
You can access the word counts in your DataviewJS scripts or custom scripts via the global object:
// Get total word count in vault
const total = window.wordCountCache.total();
// Get word count for a specific file path
const count = window.wordCountCache.get("Folder/Note.md");
Exclusions
You can configure excluded files or folders via the plugin settings. For files, the .md extension is optional.
Development
The plugin is written in JavaScript. If you prefer TypeScript, you're welcome to convert it over and open a PR.
Reload plugin in Obsidian after rebuilding via CTRL + P => Reload ....
License
MIT License. Feel free to contribute!
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.