Replace in Note
vault_replace_in_noteReplace exact text in a markdown note's body with new content. Supports optional replacement of all occurrences while preserving properties.
Instructions
Find and replace text in a markdown note's body. Matches exact text (case-sensitive). Properties are preserved; YAML formatting may be normalized to block style on first edit. Operates on the body only — properties must be edited via vault_update_properties or vault_write_note's properties parameter.
Example: vault_replace_in_note({ path: "Projects/plan.md", old_text: "TODO: write summary", new_text: "Summary complete." })
When to use: Targeted text changes within a single location — fixing typos, updating values, renaming terms, or removing a specific line (new_text=""). Replaces text in place; does not move content across sections. To relocate content between headings, use vault_replace_in_note to remove from the source (new_text=""), then vault_patch_note to append at the target. Read the note first with vault_read_note to confirm exact text.
Limitation: Exact text match only (no regex). old_text must appear in the note body or an error is returned.
Errors:
"note not found" — path does not exist; check vault_list_notes for valid paths
"text not found" — old_text does not appear in the note body; verify exact text with vault_read_note
"old_text cannot be empty" — old_text must be at least one character
Obsidian syntax: new_text is rendered as Obsidian Flavored Markdown with no escaping applied. Beyond standard Markdown, Obsidian-specific patterns (#word = tag, [[ = wikilink, %% = comment block) apply to replacement text. Verify replacements won't introduce unintended Obsidian rendering.
Returns: Confirmation message with replacement count.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Vault-relative path to the note | |
| old_text | Yes | Exact text to find (case-sensitive, non-empty) | |
| new_text | Yes | Replacement text | |
| replace_all_occurrences | No | Replace all occurrences (default: false — replaces first occurrence only) |