Back to guide/Developer Tools

Workspace Search and Replace

Cursor's Agent mode and Copilot Chat both handle multi-file operations, but both default to naive find-replace. This prompt forces contextual analysis of each occurrence. The classification step catches the edge cases that break codebases.

github-copilot-vs-cursorsearch_patternreplacement_patternfile_glob_pattern
Edit View
Prompt
Perform a codebase-wide search and replace with intelligence:

Find: {{search_pattern}}
Replace with: {{replacement_pattern}}
Scope: {{file_glob_pattern}}

But this isn't a simple find-replace. For each occurrence:

1. **Read the surrounding context** (10 lines before and after)
2. **Classify** the usage:
   - Direct usage: Replace straightforwardly
   - Aliased: Update the alias/import too
   - Inside a string/comment: May need different handling
   - In a test: Update test expectations to match
   - In a type definition: Update the type and all references
3. **Apply the appropriate replacement** for each category
4. **Update imports** if the replacement changes the import source
5. **Check for TypeScript errors** after the replacement

Provide a summary:
- Total occurrences found: X
- Replaced: Y
- Skipped (with reason): Z
- Files modified: (list)
- New TypeScript errors introduced: (list with fixes)

If any replacement is ambiguous, show the context and ask rather than guessing.

Variables to customize

{{search_pattern}}{{replacement_pattern}}{{file_glob_pattern}}

Why this prompt works

Cursor's Agent mode and Copilot Chat both handle multi-file operations, but both default to naive find-replace. This prompt forces contextual analysis of each occurrence. The classification step catches the edge cases that break codebases.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.