Skip to content

Code folding

Collapse and expand structured regions of a file — functions, blocks, classes and other language constructs — so you can focus on one part and hide the rest.

Using it

  • Fold markers ([+] / [−]) appear in a margin next to foldable lines. Click one to collapse or expand that region.
  • A collapsed region shows as a single header line with a separator drawn beneath it; expanding restores the hidden lines.
  • Jumping to a hidden line (go-to-line, a search hit, a bookmark) automatically reveals it.
  • Folding follows the syntax-colouring size limit (Preferences ▸ Syntax ▸ maximum file size, 16 MB by default): a file above it opens as plain text and has no fold margin, because fold levels are produced by the same lexer pass. Language-server features are not affected by that limit.

Commands

View menu:

Command Shortcut
Toggle Fold (the region at the caret) Ctrl+Alt+F (⌥⌘← on macOS)
Fold All Ctrl+Alt+Shift+F
Unfold All Ctrl+Alt+Shift+U

Needs a language

Folding follows the document's language structure, so the fold margin appears once a syntax colorizer is active for the file. Plain, unrecognised text has no fold regions.

In a very large file the folds appear as you go

Colouring — and with it the fold structure — is computed for what is on screen first, and for the rest of the file in the background. In a multi-megabyte file the fold markers far below the viewport therefore appear a moment later, as that background pass reaches them. Fold All waits for the whole file, so it always folds everything.