Code folding collapses and expands sections of your script, making it easier to focus on the sections that you need. PrimalScript creates foldable regions automatically from functions and subroutines, and it creates temporary foldable regions from selected text—but you can create custom persistent foldable regions for any lines in a file.
PrimalScript automatically creates foldable regions from declared functions and subroutines:
When collapsed, PrimalScript displays line numbers that show lines contained within the collapsed (or folded) region:
This ensures that line-number-based error messages remain accurate.
Whenever you select text, PrimalScript makes the selected text a temporary foldable region. You can expand and collapse these temporary regions, but they are not persisted when the file is closed and reopened.
You can create a persistent foldable region—one that is maintained even when PrimalScript and the file are opened and closed.
To create a foldable region
1.Select one or more lines of a file.
2.Click Home > in the Edit section, click Region > Create Region.
3.[Option] Edit the name of the region. The default value is Persistent fold region.
-OR-
•In your script, type #region and #endregion on commented lines.
PrimalScript uses the appropriate comment characters for each scripting language:
![]() |
![]() |
Two types of files—Powershell and SQL; chose the right comments for each one.
Named regions are especially convenient because the name remains visible even when the region is folded to remind you of what the region contains:
You can collapse (fold) and expand (unfold) foldable regions individually or as a unit.
To manage regions
•Click Home > in the Edit section, click Region:
To collapse a region
•Click the minus sign (-) at the beginning of the region:
To expand a folded region
•Click the plus sign (+) at the fold:
To collapse all foldable regions
•Click Home > in the Edit section, click Region > Hide all.
To expand all foldable regions
•Click Home > in the Edit section, click Region > Expand all.
To find foldable regions
•Search for #region
See also: