microsoft / microsoft/vscode

Warn when replacement string already exists in target files during global Search & Replace

Open
#328,447 0 comments 0 reactions 1 assignee Claimed by @osortega View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Is your feature request related to a problem? Please describe.
When performing a multi-file Search & Replace in the Search panel (left sidebar), the UI provides two main input fields: **Search** (`from`) and **Replace** (`to`).
Currently, if the value specified in the `to` field already exists as an exact match in the target files, VS Code executes the replacement without any feedback. This makes it very easy to accidentally introduce naming collisions or merge references without realizing it.
**Concrete Example:**
Suppose I set the `from` field to `Class1` and the `to` field to `Class2` across multiple files. However, `Class2` already exists in the codebase. If I execute the global replacement without realizing `Class2` is already present, it will silently merge all original `Class1` references into the existing `Class2`, causing broken logic or duplicate declaration errors that are hard to trace afterward.
### Describe the solution you'd like
When conducting a multi-file Search & Replace:
VS Code should check whether the string entered in the `to` field already has exact matches within the target files/search scope. If matches exist, VS Code should display a warning or visual indicator (e.g., *"Warning: The replacement text 'Class2' already exists 5 times in the matching scope"*).
### Describe alternatives you've considered
- **Manual search:** Manually executing a separate search for the target string (`to` field) before every replace operation. This is tedious, repetitive, and error-prone.
- **Rename Symbol (F2):** While refactoring via Language Server works for supported code symbols, global Search & Replace is frequently used across templates, configuration files, string literals, or mixed-language projects where symbol rename is unavailable.
### Additional context
A subtle warning indicator before clicking "Replace All" would prevent unintended naming collisions and data merging during bulk text replacements.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.