Replace-on-save with better VSCode integration.
This extension adds the ability to run regex replacements as a code action (it does not strictly have to be "on save")
eg.
{
// ...
"editor.codeActionsOnSave": {
"source.applyReplacements": true
},
}
source.applyReplacements
CodeActions provider which can be used in theeditor.codeActionsOnSave
setting- Command
better-replace-on-save.applyReplacements
("Apply Replacements") that can be executed from the command palette - Language-specific replacements that only apply to files of specified languages
- Comprehensive settings documentation with VS Code IntelliSense support
- Configure replacements with unique IDs to apply them individually
- Each ID-based replacement gets its own code action that can be used in
editor.codeActionsOnSave
- Command
better-replace-on-save.applySpecificReplacement
("Apply Specific Replacement") to run a single replacement by ID - Context-aware language filtering:
- ID-based replacements respect language filters when run as code actions (on save)
- ID-based replacements ignore language filters when run as direct commands (giving you flexibility to override language constraints when needed)
Configure your replacements using the following settings:
// settings.json
{
// ...
"betterReplaceOnSave.replacements": [
{
"search": "hello",
"replace": "world"
},
{
"search": "let",
"replace": "const",
"languages": [ "typescript", "javascript" ] // Optional
},
{
"id": "convertPrint", // Optional: enables specific replacement functionality
"search": "print\\(",
"replace": "logger.info(",
"languages": [ "python" ] // Optional
}
]
// ...
}
You can configure VS Code to run only specific replacements on save:
{
"editor.codeActionsOnSave": {
// Apply a specific replacement with ID "convertPrint"
"source.applyReplacements.convertPrint": true
}
}
To apply a specific replacement manually:
- Open the command palette (
Ctrl+Shift+P
orCmd+Shift+P
on Mac) - Search for "Apply Specific Replacement"
- Select the replacement by ID from the dropdown
This is particularly useful when you want to apply a replacement regardless of language restrictions.
Users appreciate release notes as you update your extension.
Initial release
Support for specific replacement code actions, and "Apply specific replacement" command.
Enjoy!