Refactor safely (Rename, Inline, Extract)¶
Understand's refactorings work from the analyzed reference graph, not from text matching. A Rename
rewrites only the references that actually resolve to the entity you picked — so a count field
doesn't get clobbered everywhere the word "count" appears in the project.
Where to find them¶
Select an entity (in source, a list, or the Information Browser) or select text in the editor, then right-click → Refactor and pick one:
| Refactoring | What it does |
|---|---|
| Rename | Rename an entity and every confirmed reference to it across the project |
| Extract Function | Pull the selected statements into a new function and call it |
| Extract Temp | Replace the selected expression with a new temporary variable |
| Inline Function | Replace calls to a function with its body |
| Inline Temp | Replace uses of a temporary with the expression it holds |
| Inline Scope | Remove a redundant scope block |
There is no factory-default keyboard shortcut for the refactorings, but each is a bindable action, so you can assign your own keys.
Why Rename beats Replace in Files¶
Understand has a separate Replace In Files command (F6) for plain text/regex search-and-replace
across files, architectures, directories, or file lists. It matches text — it has no idea which
occurrences are the symbol you mean.
Rename is different: it walks the entity's references and, at each candidate location, verifies the token there really resolves to your entity before touching it. Anything it can't confirm is reported as a warning (in a Search Results window) rather than blindly edited. For renaming a symbol, always prefer Rename over Replace in Files.
Rename covers overrides, overloads, and macros
The Refactor: Rename dialog lets you extend the rename to related entities via checkboxes —
Rename overrides (on by default), Rename overloads, and Rename in macros — shown when
they apply to the selected entity. Renaming a file entity also rewrites the matching #include
paths.
Preview before you commit¶
Every refactoring dialog offers two accept buttons:
- Apply Changes — apply directly.
- Preview Changes — open a preview window with a side-by-side Current vs Refactored diff, where you can step through and accept individual changes before committing.
Changes are written to the actual source files on disk (an open editor is reused if the file is already open, otherwise the file is loaded, patched, and saved).
Keep analysis in sync¶
Refactoring needs an up-to-date model. If you have unsaved edits or pending changes when you start, Understand asks "Would you like to save/analyze modified files before refactoring?" and offers Save and Analyze First (or Analyze First / Continue Anyway). After a refactor is applied, the affected files are re-analyzed automatically so the database stays accurate.
Undo
Made a mistake? Undo Last Refactor reverses the change — as long as the affected lines haven't been edited since. If they have, Understand tells you which files changed and asks you to restore them first.
Understand is a refactoring aid even without the tools¶
Even before you run a refactoring, the reference data is what makes restructuring safe: right-click an entity → View Information and expand the references to see everywhere it's used, called, set, or typed — see Read the Information Browser. While planning a larger restructure, annotate the sites you intend to change (notes live outside the source, so they survive the refactor) and bookmark the lines you keep returning to. Reviewing changes across commits? See Git blame & file history.