Skip to content

Reformat Code

Code | Reformat Code (⌥⌘L / Ctrl+Alt+L) re-indents the file or the selection:

  • The body of every scope is indented one level: modules, interfaces, programs, packages, classes, functions, tasks, checkers, user-defined primitives and their table … endtable, begin … end, fork … join, case items, generate regions and blocks, covergroups, clocking blocks, properties, sequences, constraint blocks, struct and enum bodies, and port, parameter and connection lists. Attributes ((* keep *)) stay where they are.
  • The single statement under if, else, a loop, wait (…), an event or delay control (@(posedge clk) ↵ x = 1;) or a case label is indented one level; a begin … end block or an else if stays at the level of its header, and a nested if is indented under the outer one.
  • End keywords, end labels and closing brackets line up with the line that opened the scope.
  • A wrapped operand lines up under the first operand (if (a && ↵ b)). Wrapped arguments and list items (ports, parameters, connections, concatenations) line up under the first item when it follows the opening bracket on the same line — a trailing comment does not change that; when the bracket ends its line, the items are indented one level. Wrapped subroutine header arguments and other wrapped lines get the continuation indent (4 spaces by default).
  • Assignments (=, <=) and binary operators get one space on each side (a+b*c → a + b * c). Ranges and selects keep their compact form ([W-1:0]), and the columns you aligned inside a line (port lists) are kept.
After Reformat Code
initial begin
if (done)
$display("done");
for (int i = 0; i < 4; i++) begin
#1;
end
fork
begin
#2;
end
join
end

One level is 2 spaces by default; set Indent and Continuation indent in Settings | Editor | Code Style | SystemVerilog | Tabs and Indents. Line breaks are not changed: the formatter re-indents lines and fixes spaces within them.

Lines are indented by the code they belong to, not by the macros around them: the `uvm_field_* lines between `uvm_object_utils_begin and `uvm_object_utils_end get the same indent as the macros, and a conditional compilation line (`ifdef, `endif) inside a class or module gets the indent of the items around it. The code of an inactive `ifdef branch is left as written (Conditional compilation).

  • Code that does not parse (see Known limitations) is not re-indented reliably: its lines keep or lose indentation, and a second Reformat Code may still move them. Correct code around it is formatted normally.
  • Wrapped call arguments always line up under the first argument; there is no setting to indent them by a fixed amount instead.
  1. Open rtl/counter.sv from the sample project, select all (⌘A / Ctrl+A) and press ⇧Tab a few times until every line starts at column 1.
  2. Press ⌥⌘L (Ctrl+Alt+L). The file is indented as before: the ports and the body one level in, the if/else branches inside always_ff one level deeper.