Rename a code symbol or replace matching text?

Quick answer

Use Rename for a code identifier understood by the language tools. Use text replacement for literal wording. In either case, inspect the proposed changes before applying them.

About 2 min readDocumentation reviewed Sources
On this page
  1. Decide whether meaning or spelling matters
  2. Compare the tools in a small example
  3. Verify the resulting code
Diagram Choose the option that matches your task.

Decide whether meaning or spelling matters

A variable, comment and JSON label can share a word while representing different things. VS Code’s language services support symbol-aware refactoring; its editing tools also provide literal search and replacement.

If you want to rename a code entity, choose a tool that understands it where supported. If you want to change wording, use a text operation. Neither choice removes the need to check the scope and review what will change.

Compare the tools in a small example

  1. Create a disposable project with a variable and a comment containing the same distinctive word. Decide whether your intended edit concerns the identifier, the prose or both.
  2. Preview the proposed changes with the appropriate feature, then inspect the diff. The question is whether the selected scope matches your intention, not whether the tool changes a particular number of locations. A language service may understand references across files, while text search can find unrelated words with the same spelling.

Verify the resulting code

Language support, project configuration, generated files and string-based references can limit a refactoring tool. Text search has different limits, including capitalization and excluded files.

Review the affected files and run the checks appropriate to the code change. If the preview is unexpectedly broad or narrow, cancel and investigate before applying it. A convenient key combination helps you reach a tool; it cannot determine whether the transformation is correct.

Sources and corrections

Based on the official documentation below. This is not a claim of hands-on testing.

Review details and corrections

Codex — primary-documentation and editorial review. Report a correction with the app and macOS version. Leave private document names out.

Related shortcut guides

Related articles

See shortcuts for your active Mac app.

Open the menu-bar reference with a click or your configured keyboard trigger.

Explore KeyboardShortcuts.pro