Skip to content

Folding

Folding hides the body of a block and shows only its first and last line, so a long file fits on one screen and you can find your way around it. Folding never edits the text: you can fold and unfold as you like.

The steps use the sample project. The caret is the text cursor.

  1. Open rtl/counter.sv and click at the end of the line always_ff @(posedge clk or negedge rst_n) begin : seq.
  2. Press ⌘- (macOS) / Ctrl+- (Windows/Linux), or choose Code | Folding | Collapse. The body between begin : seq and end : seq collapses to ...: the line now reads always_ff @(posedge clk or negedge rst_n) begin : seq...end : seq. Only this block is folded; the blocks outside it stay open. (If a smaller block, such as an inner if, folded instead, the caret was inside it: press ⌘+ / Ctrl+= to expand it, click at the end of the always_ff line (after seq) and try again.)
  3. Press ⌘+ (Ctrl+=) to expand it again. The file is unchanged: folding does not edit the text.
  4. Press ⌘⇧- (Ctrl+Shift+-) to collapse everything in the file at once, then ⌘⇧+ (Ctrl+Shift+=) to expand all. You can also click the small fold marker next to a block in the gutter (the strip beside the line numbers).

These fold when they span more than one line:

  • the bodies of modules, interfaces, programs, packages, classes, interface classes, functions, tasks, constructors, covergroups, clocking blocks, properties, sequences, checkers and user-defined primitives;
  • begin … end (also with a label), fork … join, case … endcase, randcase, generate … endgenerate and generate blocks;
  • multi-line comments, shown as /*...*/;
  • the code of an inactive `ifdef branch (a branch the current defines switch off, greyed out; see Conditional compilation), shown as ...: the directives stay visible.

A collapsed scope keeps its header and end keyword visible:

Collapsed
always_ff @(posedge clk or negedge rst_n) begin : seq...end : seq

Empty bodies (only blank lines) do not fold. Port and argument lists and { … } bodies (constraints, structs, coverpoint bins) do not fold.

You see Likely cause What to do
Nothing collapses The block is on one line, or its body is empty, or it is a kind that does not fold (a port list, a { … } body) Fold a block of several lines, such as the always_ff body above
A smaller block collapsed The caret was inside an inner block Put the caret on the line of the block you want
No fold markers or shortcuts work The file is not a SystemVerilog file, or the plugin is disabled See Installation
The shortcut does nothing Your keymap differs, or on a laptop the key needs Fn Use Code | Folding in the menu