Rename
Renaming a name with find-and-replace changes things that merely look alike. Rename is scope-aware: it changes only the names that refer to this declaration, in all files, and checks first that the new name keeps the meaning of your code. Click a name, a declaration or any usage of it (the blinking text cursor is the caret), and choose Refactor | Rename… (⇧F6 on macOS, Shift+F6 on Windows/Linux). In the Rename dialog (a field with the current name, a few checkboxes, and Refactor and Cancel buttons; the IDE may instead let you type the new name in place and press Enter), type the new name and click Refactor. The declaration and every usage that Find Usages would list are updated, in all files.
The Search in comments and strings checkbox is off by default, which is what you want in the steps below. Tick it only if you also want matching words in comments and string literals changed.
What the video shows
- In
classes/shapes.sv, the caret is on the virtual methodareaof classshape; ⇧F6 (Shift+F6) opens the Rename dialog. - The new name
get_areais entered and Refactor is clicked. - The overrides in
squareandcircleand the calls.area()are renamed too.
Nearly every declared construct can be renamed (not checkers or user-defined primitives) — see Supported constructs. Before changing anything, the plugin checks that the rename keeps the meaning of your code; if it would not, you get a list of conflicts first.
Try it
Section titled “Try it”Open the sample project and wait until indexing has finished (the progress bar at the bottom right disappears). You do not need to change sim.f: files in the project folder that it does not list (rtl/legacy_reg.v, classes/shapes.sv) are renamed too. If the IDE renames in place instead of showing a dialog, type the new name and press Enter; in every step below, “click Refactor” means that. To check a step, open each file it names and look at the quoted line. Undo after each step with Edit | Undo (⌘Z / Ctrl+Z) while an editor tab is focused; one undo reverts the rename in every file. Check that the names are back before the next step (for example module counter in rtl/counter.sv). Besides the files named in a step, the body of the macro COUNTER in rtl/defines.svh (counter __name (.clk(__clk), …); the macro keeps its name) also follows renames of counter and its ports: that is the Macro bodies row in What is renamed together.
- Open
rtl/counter.sv, put the caret oncounterinmodule counter, press ⇧F6 (Shift+F6), typeup_counterand click Refactor. The module and its end labelendmodule : up_counterchange, and so do the instantiation inrtl/top.svand the body of the macroCOUNTERinrtl/defines.svh:counter __name (…)becomesup_counter __name (…); the macro is still namedCOUNTER. - In
rtl/counter.sv, rename the portclktoclock.@(posedge clock …)is updated, and inrtl/top.svthe implicit connection.clkbecomes.clock(clk), and.clk(__clk)inside the body of the macroCOUNTERbecomes.clock(__clk). - In
rtl/top.sv, put the caret onrst_nin the module headermodule top(input logic clk, input logic rst_n);and rename it toreset_n. The implicit connection.rst_nbecomes.rst_n(reset_n): the port ofcounteris a different declaration, so only the signal intopis renamed. - Open
rtl/legacy_reg.vand renameqinoutput [7:0] q;todout. The port list, theoutputdeclaration, theregdeclaration and the assignment all change. - Open
classes/shapes.sv, put the caret onareainvirtual function real area();insideclass shape(the first one in the file) and rename it toget_area. The overrides insquareandcircleand the calls.area()are renamed too. - In
rtl/top.sv, renamebusyinlogic busy;toactive. Inrtl/top.sv,initial $display(g_lane[0].busy);becomes… g_lane[0].active …(a hierarchical reference: block name, then signal). - In
rtl/counter_pkg.sv, rename the enum memberIDLEtoRESET.rtl/counter.svpulls in the names ofcounter_pkgwithimport counter_pkg::*;, sostate <= IDLE;becomesstate <= RESET;.
If every step matched, Rename works on your installation. If one did not, see If it doesn’t work.
What is renamed together
Section titled “What is renamed together”Some declarations belong together and are always renamed as a group:
| Situation | What happens |
|---|---|
| End labels | endmodule : counter, endclass : my_item, endfunction : f, end : seq follow the name. |
| Virtual methods | Renaming a virtual method renames the whole override family: the base declaration and every override in derived classes, plus all calls. You can start from the base method or from any override. |
| Constraints | Constraints override by name, so renaming one renames the constraints of that name in base and derived classes, the out-of-block bodies (constraint C::c_x {…}) and uses such as item.c_x.constraint_mode(0). |
| Macro bodies | A `define body that instantiates the module by name follows the rename of the module, of its ports and of its parameters: .state_i ( __d ) becomes .state_x ( __d ) in the macro, so every instance the macro’s calls create stays connected. Line continuations (\) are kept. Renaming to one of that macro’s formals is a conflict: every call would replace the name with its argument. |
| Covergroups | Renaming a covergroup also renames its endgroup : label and its uses (cg = new;, w.cg.sample()). |
| Verilog-95 ports | In module m(clk, q); output [7:0] q; reg [7:0] q; the port list entry, the output declaration and the reg/wire declaration are one signal and are renamed together. |
| Implicit port connections | .clk is SystemVerilog’s shorthand for .clk(clk): it connects a port and a signal of the same name. Renaming either one rewrites it as an explicit connection: .clock(clk) when the port is renamed, .clk(clock) when the signal is. |
| Generate branches | A label or signal declared in mutually exclusive if/else generate branches is one name; renaming it renames every branch, so hierarchical references stay valid. |
| Duplicate definitions | If the same module or function is defined in several files (for example alternatives selected with `ifdef), usages refer to all of them, so all definitions are renamed. A dialog lists the extra definitions first (see Rename conflicts). |
| verilog-mode AUTO_TEMPLATEs | A module’s name at the head of an AUTO_TEMPLATE comment (/* legacy_reg AUTO_TEMPLATE () in a file with its instances, or in its own file, is renamed with the module, so Expand AUTOs still applies the template. As verilog-mode reads heads: only one starting its line counts (not after code), and the name matches without case (/* Sub AUTO_TEMPLATE is renamed too). Find Usages lists heads written in the module’s case, in any file. |
With the default options, text in comments (other than AUTO_TEMPLATE heads) and in string literals is not changed: after renaming the property vif, the configuration
key in uvm_config_db#(virtual my_if)::get(this, "", "vif", vif) is still "vif".
If it doesn’t work
Section titled “If it doesn’t work”| You see | Likely cause | What to do |
|---|---|---|
| Refactor | Rename… is greyed out, or nothing is renamed | The caret is not on a name, or indexing is not finished | Click the name itself; wait for the progress bar at the bottom right |
| A usage was not renamed | It is in inactive `ifdef code, in a comment or string, or in a file outside the project folder or attached as a library (library files are never modified) |
See Conditional compilation and Known limitations; tick Search in comments and strings for text |
| A dialog lists conflicts | The new name would change what some code refers to | See Rename conflicts; pick another name or Cancel |
Examples
Section titled “Examples”// rtl/top.sv, beforecounter #(.MAX(20)) u_counter(.clk, .rst_n, .count(count), .done(done));// aftercounter #(.MAX(20)) u_counter(.clock(clk), .rst_n, .count(count), .done(done));module legacy_reg(clk, d, q); output [7:0] q; reg [7:0] q; always @(posedge clk) q <= d;module legacy_reg(clk, d, dout); output [7:0] dout; reg [7:0] dout; always @(posedge clk) dout <= d;Limitations
Section titled “Limitations”- Names written inside a macro definition are not updated, except when the body instantiates the module (see Macro bodies above). Macro names themselves are renamed like any other name: see Macros.
- Files attached as libraries are never modified. If a rename would require it — for example renaming a method that overrides a method of a library class — you get a conflict instead.
- If the base class is not available at all (for example the UVM library is not in the project), renaming a method that overrides a base-class method cannot be checked: the rename goes ahead and the method no longer overrides the base method.
- See Known limitations for the complete list.