Skip to content

Folding Ranges ​

Blocks ​

Braces fold: namespaces, types, functions, lambdas and the bodies of statements.

Supported

Brace blocks

Namespaces, types, functions and lambdas fold at their braces

Supported

Statement bodies

The bodies of control-flow statements and bare blocks fold

Each branch of an if/else or a try/catch folds on its own: the line that closes one branch and opens the next stays visible.

Supported

Linkage specification blocks

extern "C" blocks form folding ranges, also behind the usual __cplusplus guards

Lists ​

Any parentheses, brackets or braces spanning lines fold, and so do template parameter and argument lists.

Supported

Multi-line lists

Multiline parameter, argument, initializer and capture lists form folding ranges

Supported

Template parameter lists

Multiline template parameter lists fold on their angle brackets

Class, function, variable and alias templates, partial specializations, the lists an out-of-line member definition repeats, template template parameters and lambdas with explicit template parameters all fold their parameter lists.

Supported

Every bracket pair

Any parentheses, brackets or braces spanning lines fold, whatever writes them

Conditions, casts, static_assert, parenthesized expressions, subscripts, attribute lists, function types and the arguments of a macro invocation fold like a call's arguments do. An attribute list written [[...]] folds once.

Sections ​

The members under an access specifier, and the statements under a case label, fold as a section up to the next label.

Supportedclangd#1455

Access-specifier sections

Access-specifier regions within a class form folding ranges

Supported

Switch cases

Each case of a switch folds up to the next label, which stays visible

Labels written one after another fold as one case. A case whose body is a block opening on the label's line folds as that block.

Comments and Runs ​

A block comment folds on its delimiters, and consecutive line comments, includes, imports or using declarations fold as one run.

Supported

Comments

Multiline block comments and runs of line comments fold

Line comments on consecutive lines fold as one run below the first line, which stays visible; a blank line or a line of code ends the run. A block comment folds on its delimiters like a brace pair. A comment trailing code does not fold.

Supported

Include runs

Consecutive include directives fold as one run below the first include

Blank lines and comment lines between includes stay in the run; code or another directive ends it. Includes inside a conditional branch fold within it, whether or not the branch is taken.

Supported

using declaration runs

Consecutive using declarations and directives fold below the first one

A blank line or any other line ends the run, and alias declarations do not join one, nor does a declaration sharing its line with other code. Using declarations produced by macros fold at the invocations.

Supported

Import runs

Consecutive import declarations fold as one run, like include directives

export import joins the run too, and blank and comment lines between imports stay in it.

Raw Strings ​

A raw string literal spanning lines folds on its delimiters.

Supported

Raw string literals

Multiline raw string literals fold on their delimiters

The placeholder repeats the encoding prefix, a custom delimiter and a literal suffix. A raw string written in a macro argument folds where it is written.

Preprocessor Conditionals ​

Each branch of a conditional folds up to the directive that ends it, taken or not, and so do the blocks inside an untaken one.

Preprocessor conditionals

Each branch of a conditional forms a folding range up to the directive that ends it, which stays visible

A branch that would cut across a block or a section, such as the #ifdef __cplusplus around extern "C" { in a C header, gives way to it, so the folds always nest.

Supported

Untaken branches

Untaken branches fold like taken ones

Every branch of a conditional folds whether or not the compile takes it, conditionals nested in an untaken branch included, so dead code can be folded away by hand. Untaken code is dimmed by the inactive modifier of semantic tokens; the folds themselves do not tell the branches apart.

Supported

Blocks in untaken branches

The blocks of an untaken branch fold too, not only the branch as a whole

A function, a class or a statement body in code the compile skips folds on its brackets, so dead code can be folded piece by piece.

Pragma Regions ​

#pragma region and #pragma endregion fold the code between them.

Supportedclangd#1623

Pragma regions

Named pragma regions form folding ranges

Modules ​

The module fragments and export blocks of a module unit fold.

Supported

Module fragments and export blocks

The global and private module fragments and export blocks form folding ranges

Macros ​

Code spelled through a macro, or written in its arguments, folds where you see it.

Supported

Blocks spelled by macros

Braces and access specifiers spelled through macros fold at the invocation site

A block a macro opens and closes folds between the two invocations, which stay visible; its placeholder is ....

Supported

Code in macro arguments

Code written inside macro arguments folds where it is written

Folding Whole Lines ​

A client folding whole lines keeps what a reader needs on screen: a body folds from the line holding its declaration's name, and a client showing collapsed text folds the closing line in.

Supportedclangd#2666

Declaration-line folding

A declaration's body folds from the line holding its name

When the opening brace sits below the name, on a line of its own or after a signature spanning several lines, a client that folds whole lines starts the fold on the name's line, so the folded declaration still shows what it is. A client folding by characters starts at the brace and keeps everything before it visible anyway.

Client support: VS Code leaves the closing } on a line of its own rather than joining it to the signature line (vscode#3352); Neovim joins it (see "Closing lines fold in").

Supported

Closing lines fold in

A client that shows collapsed text folds a block's closing line too, int area(Point p) {...}

Each fold shows its first line followed by ...; when the closing brace, #endif or */ sits on a line of its own, that line folds in and shows after the .... A closing line that opens the next block, such as } else {, stays visible.

Client support: Neovim shows the text through vim.lsp.foldtext(). VS Code shows no collapsed text, so the closing line stays visible there (vscode#3352).

Presentation ​

A folded range shows a placeholder for what it hides, and a fold that would hide nothing is not offered.

Supportedclangd#2667

Collapsed text

A folded range shows a placeholder, such as {...} for a body, while the line it starts on stays visible

A client folding by characters, such as Zed, shows the placeholder in place of the range. A client folding whole lines, such as Neovim, shows its text in place of the whole first line, so it gets the first line followed by ... instead (see "Closing lines fold in").

Client support: VS Code does not show collapsedText (vscode#70794). A client that ignores it still folds, without the placeholder.

Supported

Single-line constructs stay unfolded

A fold that hides nothing is noise