Auto Replacer
approvedby Alecell
Replace text in your notes automatically using regex rules and JavaScript functions.
πͺ Auto Replacer β Obsidian Plugin
Auto Replacer is a powerful plugin for Obsidian that automatically replaces text in your notes using custom rules powered by regex and JavaScript.
Whether you want to format units, highlight keywords, or inject smart, context-aware replacements like the note title, Auto Replacer gives you full control over text automation in your vault.
π¦ Features
- π Define your own Regex patterns
- π§ Write JavaScript transform functions to control how matches are replaced
- πΎ Rules are saved and editable via a visual UI
- β¨ No need to edit markdown manually or click on a button, just type and Auto Replacer will do the rest
π οΈ How it Works
Each rule consists of:
- Regex Pattern β What you want to match (e.g.,
\bkm\b) - Transform Function β How to replace it (e.g.,
*kilometers*) - Trigger β Runs automatically on editor change, with debounce to prevent performance issues
Example:
// Match the note title and make it bold
function transformNoteTitle(occurrence, editor, file) {
const noteName = file?.basename;
if (!noteName) return occurrence.original;
return `**${noteName}**`;
}
π Example Rules
| Name | Text | Pattern | Replace With |
|---|---|---|---|
| Replace Note Title | world of pados | (?<!\*\*)\b{{file.basename}}\b(?!\*\*) | **World of Pados** |
| Replace Comma Decimal | 27,6 | \b\d+,\d+\b | 27.6 |
| Replace Fahrenheit | 64.4 Β°F | \b\d+(\.\d+)?\s?Β°?\s?F\b | 18 Β°C |
| Emphasize Measurement | 49 km | \b\d+(?:\.\d+)?\s\*(?:km|mi|kg|g|m)\b | *49 km* |
π How to Use
-
Open Settings β Auto Replacer
-
Click "Add custom rule"
-
Fill out:
Rule nameRule IDRegex patternand FlagsReplacement code(in JavaScript)Description(optional)
-
Save and type in any note β the rule applies automatically
π§ Advanced Usage
- You can reference
editorandfileobjects inside your transform code - Use
{{file.basename}}as a dynamic variable in regex patterns - Debounce is automatically applied on
editor-changefor performance
π¨ Limitations & Considerations
- Avoid writing transform functions that return unchanged text since it may cause unnecessary loops
- Despite the fact that I tested it with book-size notes without problems, it also have a concern when we have too many patterns found on the same file without reasonable gaps between them, but since the word hobbit is mentioned only 400 times on LOtR I think it'll not be a problem.
π Only Run Code You Understand
The Auto Replacer plugin allows you to write and execute custom JavaScript functions to dynamically transform matched content within your notes. These functions are executed locally, directly in your Obsidian vault, and are never transmitted anywhere.
However, executing arbitrary code β even if it looks innocent β can have unintended consequences. You have full control over what the plugin runs, which also means you take full responsibility for what it does. A simple typo can break your notes. A badly written loop can slow down your editor. And a malicious snippet (if ever copied from somewhere) could do far worse.
So please β only run code that you fully understand.
Auto Replacer offers you the power to automate and enhance your note-taking... But as a certain wise uncle once said:
With great power comes great responsibility.
π Documentation
| Section | Link |
|---|---|
| Learn More | π Documentation |
| Plugin on GitHub | π GitHub Repo |
| Submit Issue | π Report |
π Support the Plugin β Buy Me a Dragon
Creating and maintaining this plugin takes time, research, and a lot of coffee (or should I say... dragons?).
If you found AutoReplacer useful and want to support its development, consider fueling it with a mythical boost!
Your support helps improve the plugin and means a lot π
π₯ Credits
Created with β€οΈ by Alecell. Special thanks to sailKite!
π License
MIT License Β© Alecell
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.
