How do I collapse sections of code in Visual Studio Code for Windows?
How do I fold or collapse sections of code in Visual Studio Code?
Is this feature supported?
visual-studio-code
add a comment |
How do I fold or collapse sections of code in Visual Studio Code?
Is this feature supported?
visual-studio-code
4
Does#regionwork in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.
– Drew Kennedy
May 6 '15 at 13:07
5
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
1
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54
add a comment |
How do I fold or collapse sections of code in Visual Studio Code?
Is this feature supported?
visual-studio-code
How do I fold or collapse sections of code in Visual Studio Code?
Is this feature supported?
visual-studio-code
visual-studio-code
edited Dec 15 '18 at 17:59
Peter Mortensen
13.5k1983111
13.5k1983111
asked May 6 '15 at 4:50
Nick
3,00131119
3,00131119
4
Does#regionwork in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.
– Drew Kennedy
May 6 '15 at 13:07
5
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
1
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54
add a comment |
4
Does#regionwork in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.
– Drew Kennedy
May 6 '15 at 13:07
5
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
1
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54
4
4
Does
#region work in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.– Drew Kennedy
May 6 '15 at 13:07
Does
#region work in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.– Drew Kennedy
May 6 '15 at 13:07
5
5
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
1
1
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54
add a comment |
14 Answers
14
active
oldest
votes
This feature has been rolled out and is now implemented since Visual Studio Code version 0.10.11 (see these release notes). There are these keyboard shortcuts available:
Fold folds the innermost uncollapsed region at the cursor:
Ctrl + Shift + [ on Windows
⌥ + ⌘ + [ on macOS
Unfold unfolds the collapsed region at the cursor:
Ctrl + Shift + ] on Windows
⌥ + ⌘ + ] on macOS
Fold All folds all region in the editor:
Ctrl + K, Ctrl + 0 (zero) on Windows
⌘ + K, ⌘ + 0 (zero) on macOS
Unfold All unfolds all regions in the editor:
Ctrl + K, Ctrl + J on Windows
⌘ + K, ⌘ + J on macOS
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
|
show 7 more comments
As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs.
The default keys are:
Fold All: CTRL+K, CTRL+0 (zero)
Fold Level [n]: CTRL+K, CTRL+[n]*
Unfold All: CTRL+K, CTRL+J
Fold Region: CTRL+K, CTRL+[
Unfold Region: CTRL+K, CTRL+]
*Fold Level: to fold all but the most outer classes, try CTRL+K, CTRL+1
Macs: use ⌘ instead of CTRL (thanks Prajeet)
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
Thanks,ctrl + 0in the other answer didn't make sense;Fold Level [n]rationalized it for me.
– Dan Marshall
Apr 13 '17 at 22:06
|
show 4 more comments
This feature is available in the standard build now. To make the collapse/expand controls appears, you need to mouse over the area just to the right of the line numbers as shown in this screenshot:

what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
add a comment |
Code folding by regions has arrived with v1.17. Folding by regions documentation. And v1.19 and 1.23.
TypeScript/JavaScript: //#region and //#endregion and //region and //endregion
C#: #region and #endregion
C/C++: #pragma region and #pragma endregion
F#: //#region and //#endregion
PowerShell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
PHP: #region and #endregion
Bat: ::#region and ::#endregion
Each language also has snippets available for the markers. Type '#' and invoke code completion to see them. To have region markers configured for your language, contact the language extension provider.
v1.23 added CSS/SCSS/Less code folding regions:
CSS/SCSS/Less: /* #region */ and /* #endregion */ or /*#region*/ and /*#endregion*/
SCSS/Less: // #region and // #endregion
1
// regionand// endregionare not working with VS Code version 1.22 (haven't tested versions below or above that though). But// #regionand// #endregionworks (note the '#' and space in both). This way ESLint (if you are using) won't show error ifspaced-commentrule is on (i.e. not set to 'off' or 0).
– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually/* #region Foo Bar */and/* #endregion */
– toddmo
May 22 '18 at 1:18
At least in Python,# regionand# endregionwork if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie# region Example Heading.
– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
add a comment |
The default shortcut for collapse/extend are:
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + [ "Fold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Fold all"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + ] "Unfold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Unfold all"
Or go to keybindings.json and change as you wish.
For example:
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
,
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
,
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
Please review this:ctrl+shift+alt+[ "Unfold all"You wrote[instead of]. Correct me if I am wrong.
– fWd82
May 18 '17 at 7:50
add a comment |
You should add user settings:
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
add a comment |
Collapsing is now supported in release 1.0:
Source Code Folding Shortcuts
There are new folding actions to collapse source code regions based on
their folding level.
There are actions to fold level 1 (Ctrl+K Ctrl+1) to level 5 (Ctrl+K
Ctrl+5). To unfold, use Unfold All (Ctrl+Shift+Alt+]).
The level folding actions do not apply to region containing the
current cursor.
I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. (Or two buttons left and one down starting from the backspace button.)
add a comment |
If none of the shortcuts are working (like for me), as a workaround you can also open the command palette (Ctrl + 3 or View -> Command Palette...) and type in fold all:

add a comment |
As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient.
Any line followed by an indented line will have a '-' character to allow collapse. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block.
The (Ctrl + Shift + Alt + ]) will still affect all blocks, closing one level. Each repeated use closed one more level. The (Ctrl + Shift + Alt + [) works in the opposite way.
Hooray, block collapse finally works usefully.
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
add a comment |
With JavaScript:
//#region REGION_NAME
...code here
//#endregion
add a comment |
On a Mac, it's the RHS Command key, ⌘K, not the left for the code folding commands.
Otherwise the left hand Command key will delete the current line, ⌘K.
add a comment |
This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.
Example:

add a comment |
I wish Visual Studio Code could handle:
#region Function Write-Log
Function Write-Log
...
#endregion Function Write-Log
Right now Visual Studio Code just ignores it and will not collapse it.
Meanwhile Notepad++ and PowerGUI handle this just fine.
Update: I just noticed an update for Visual Studio Code. This is now supported!
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
add a comment |
In the windows build the shortcut is set to Alt + 0
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30067767%2fhow-do-i-collapse-sections-of-code-in-visual-studio-code-for-windows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
This feature has been rolled out and is now implemented since Visual Studio Code version 0.10.11 (see these release notes). There are these keyboard shortcuts available:
Fold folds the innermost uncollapsed region at the cursor:
Ctrl + Shift + [ on Windows
⌥ + ⌘ + [ on macOS
Unfold unfolds the collapsed region at the cursor:
Ctrl + Shift + ] on Windows
⌥ + ⌘ + ] on macOS
Fold All folds all region in the editor:
Ctrl + K, Ctrl + 0 (zero) on Windows
⌘ + K, ⌘ + 0 (zero) on macOS
Unfold All unfolds all regions in the editor:
Ctrl + K, Ctrl + J on Windows
⌘ + K, ⌘ + J on macOS
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
|
show 7 more comments
This feature has been rolled out and is now implemented since Visual Studio Code version 0.10.11 (see these release notes). There are these keyboard shortcuts available:
Fold folds the innermost uncollapsed region at the cursor:
Ctrl + Shift + [ on Windows
⌥ + ⌘ + [ on macOS
Unfold unfolds the collapsed region at the cursor:
Ctrl + Shift + ] on Windows
⌥ + ⌘ + ] on macOS
Fold All folds all region in the editor:
Ctrl + K, Ctrl + 0 (zero) on Windows
⌘ + K, ⌘ + 0 (zero) on macOS
Unfold All unfolds all regions in the editor:
Ctrl + K, Ctrl + J on Windows
⌘ + K, ⌘ + J on macOS
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
|
show 7 more comments
This feature has been rolled out and is now implemented since Visual Studio Code version 0.10.11 (see these release notes). There are these keyboard shortcuts available:
Fold folds the innermost uncollapsed region at the cursor:
Ctrl + Shift + [ on Windows
⌥ + ⌘ + [ on macOS
Unfold unfolds the collapsed region at the cursor:
Ctrl + Shift + ] on Windows
⌥ + ⌘ + ] on macOS
Fold All folds all region in the editor:
Ctrl + K, Ctrl + 0 (zero) on Windows
⌘ + K, ⌘ + 0 (zero) on macOS
Unfold All unfolds all regions in the editor:
Ctrl + K, Ctrl + J on Windows
⌘ + K, ⌘ + J on macOS
This feature has been rolled out and is now implemented since Visual Studio Code version 0.10.11 (see these release notes). There are these keyboard shortcuts available:
Fold folds the innermost uncollapsed region at the cursor:
Ctrl + Shift + [ on Windows
⌥ + ⌘ + [ on macOS
Unfold unfolds the collapsed region at the cursor:
Ctrl + Shift + ] on Windows
⌥ + ⌘ + ] on macOS
Fold All folds all region in the editor:
Ctrl + K, Ctrl + 0 (zero) on Windows
⌘ + K, ⌘ + 0 (zero) on macOS
Unfold All unfolds all regions in the editor:
Ctrl + K, Ctrl + J on Windows
⌘ + K, ⌘ + J on macOS
edited Dec 15 '18 at 18:14
Peter Mortensen
13.5k1983111
13.5k1983111
answered May 6 '15 at 13:00
Brocco
39.3k75171
39.3k75171
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
|
show 7 more comments
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
4
4
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
Sorry, here's the link to their roadmap.
– daemonaka
Jan 14 '16 at 11:54
5
5
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
This was just released. You have to download the insider release of VSCode. code.visualstudio.com/insiders. After install make sure there is a setting in the workspace or user settings called "editor.folding". The value should be true. If you don't see that setting you are not on the current version 0.10.10. I had to wait until my installation found the latest version. See the release notes. github.com/Microsoft/vscode-docs/blob/vnext/release-notes/…
– Rentering.com
Feb 29 '16 at 16:59
7
7
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
June 2016 update: Fold All: ctrl+k, ctrl+0, Unfold All: ctrl+k, ctrl+j
– Michael Fulton
Jun 23 '16 at 20:43
1
1
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
For AZERTY (French) keyboard users: Ctrl-K + Ctrl-à does the Collapse All operation (not Ctrl-K + Ctrl+Shift+0)
– WoJ
Jul 31 '17 at 14:53
2
2
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
IMHO the key choices are not easily memorable, why did they choose each? Anyone have a mnemonic or other memory trick for these?
– jasonleonhard
Sep 13 '17 at 22:51
|
show 7 more comments
As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs.
The default keys are:
Fold All: CTRL+K, CTRL+0 (zero)
Fold Level [n]: CTRL+K, CTRL+[n]*
Unfold All: CTRL+K, CTRL+J
Fold Region: CTRL+K, CTRL+[
Unfold Region: CTRL+K, CTRL+]
*Fold Level: to fold all but the most outer classes, try CTRL+K, CTRL+1
Macs: use ⌘ instead of CTRL (thanks Prajeet)
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
Thanks,ctrl + 0in the other answer didn't make sense;Fold Level [n]rationalized it for me.
– Dan Marshall
Apr 13 '17 at 22:06
|
show 4 more comments
As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs.
The default keys are:
Fold All: CTRL+K, CTRL+0 (zero)
Fold Level [n]: CTRL+K, CTRL+[n]*
Unfold All: CTRL+K, CTRL+J
Fold Region: CTRL+K, CTRL+[
Unfold Region: CTRL+K, CTRL+]
*Fold Level: to fold all but the most outer classes, try CTRL+K, CTRL+1
Macs: use ⌘ instead of CTRL (thanks Prajeet)
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
Thanks,ctrl + 0in the other answer didn't make sense;Fold Level [n]rationalized it for me.
– Dan Marshall
Apr 13 '17 at 22:06
|
show 4 more comments
As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs.
The default keys are:
Fold All: CTRL+K, CTRL+0 (zero)
Fold Level [n]: CTRL+K, CTRL+[n]*
Unfold All: CTRL+K, CTRL+J
Fold Region: CTRL+K, CTRL+[
Unfold Region: CTRL+K, CTRL+]
*Fold Level: to fold all but the most outer classes, try CTRL+K, CTRL+1
Macs: use ⌘ instead of CTRL (thanks Prajeet)
As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs.
The default keys are:
Fold All: CTRL+K, CTRL+0 (zero)
Fold Level [n]: CTRL+K, CTRL+[n]*
Unfold All: CTRL+K, CTRL+J
Fold Region: CTRL+K, CTRL+[
Unfold Region: CTRL+K, CTRL+]
*Fold Level: to fold all but the most outer classes, try CTRL+K, CTRL+1
Macs: use ⌘ instead of CTRL (thanks Prajeet)
edited Dec 16 '18 at 20:53
answered Jun 23 '16 at 20:42
Michael Fulton
2,05011028
2,05011028
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
Thanks,ctrl + 0in the other answer didn't make sense;Fold Level [n]rationalized it for me.
– Dan Marshall
Apr 13 '17 at 22:06
|
show 4 more comments
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
Thanks,ctrl + 0in the other answer didn't make sense;Fold Level [n]rationalized it for me.
– Dan Marshall
Apr 13 '17 at 22:06
6
6
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
For people like me who are not so familiar with with the VS notation --- ctrl + k, ctrl + 0 === ctrl+k,0. You do not press ctrl+k, then 0.
– Cody G.
Sep 2 '16 at 12:42
3
3
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
@CodyG. Thanks for pointing that out. When I use chords I think about about them in terms of Ctrl * (K + 0), distributing the Ctrl lol. I've updated my answer to be more clear.
– Michael Fulton
Oct 7 '16 at 16:24
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
Does it save and restore the state of folds between IDE start/shut down?
– Green
Nov 20 '16 at 14:58
3
3
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
Try cmd instead of ctrl if ctrl doesn't work.
– Prajeet Shrestha
Dec 21 '16 at 4:46
1
1
Thanks,
ctrl + 0 in the other answer didn't make sense; Fold Level [n] rationalized it for me.– Dan Marshall
Apr 13 '17 at 22:06
Thanks,
ctrl + 0 in the other answer didn't make sense; Fold Level [n] rationalized it for me.– Dan Marshall
Apr 13 '17 at 22:06
|
show 4 more comments
This feature is available in the standard build now. To make the collapse/expand controls appears, you need to mouse over the area just to the right of the line numbers as shown in this screenshot:

what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
add a comment |
This feature is available in the standard build now. To make the collapse/expand controls appears, you need to mouse over the area just to the right of the line numbers as shown in this screenshot:

what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
add a comment |
This feature is available in the standard build now. To make the collapse/expand controls appears, you need to mouse over the area just to the right of the line numbers as shown in this screenshot:

This feature is available in the standard build now. To make the collapse/expand controls appears, you need to mouse over the area just to the right of the line numbers as shown in this screenshot:

edited Dec 15 '18 at 18:23
Peter Mortensen
13.5k1983111
13.5k1983111
answered Sep 8 '16 at 17:17
BraveNewMath
4,87623244
4,87623244
what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
add a comment |
what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
what if I want to collapse code after commenting all the function but there is no collapse button. any idea?
– Harsh Patel
May 1 '18 at 12:40
2
2
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
Is there a way to permanently display the collapse controls? TIA
– Tuan Trinh
Jun 13 '18 at 10:26
1
1
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
I was using this but suddenly it disappears. I don't know what's wrong.
– Robin Garg
Jun 18 '18 at 12:35
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
Was this feature removed? Not seeing it on 1.27.2
– Alex
Nov 20 '18 at 18:55
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
the feature is still there for me
– BraveNewMath
Dec 8 '18 at 3:25
add a comment |
Code folding by regions has arrived with v1.17. Folding by regions documentation. And v1.19 and 1.23.
TypeScript/JavaScript: //#region and //#endregion and //region and //endregion
C#: #region and #endregion
C/C++: #pragma region and #pragma endregion
F#: //#region and //#endregion
PowerShell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
PHP: #region and #endregion
Bat: ::#region and ::#endregion
Each language also has snippets available for the markers. Type '#' and invoke code completion to see them. To have region markers configured for your language, contact the language extension provider.
v1.23 added CSS/SCSS/Less code folding regions:
CSS/SCSS/Less: /* #region */ and /* #endregion */ or /*#region*/ and /*#endregion*/
SCSS/Less: // #region and // #endregion
1
// regionand// endregionare not working with VS Code version 1.22 (haven't tested versions below or above that though). But// #regionand// #endregionworks (note the '#' and space in both). This way ESLint (if you are using) won't show error ifspaced-commentrule is on (i.e. not set to 'off' or 0).
– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually/* #region Foo Bar */and/* #endregion */
– toddmo
May 22 '18 at 1:18
At least in Python,# regionand# endregionwork if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie# region Example Heading.
– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
add a comment |
Code folding by regions has arrived with v1.17. Folding by regions documentation. And v1.19 and 1.23.
TypeScript/JavaScript: //#region and //#endregion and //region and //endregion
C#: #region and #endregion
C/C++: #pragma region and #pragma endregion
F#: //#region and //#endregion
PowerShell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
PHP: #region and #endregion
Bat: ::#region and ::#endregion
Each language also has snippets available for the markers. Type '#' and invoke code completion to see them. To have region markers configured for your language, contact the language extension provider.
v1.23 added CSS/SCSS/Less code folding regions:
CSS/SCSS/Less: /* #region */ and /* #endregion */ or /*#region*/ and /*#endregion*/
SCSS/Less: // #region and // #endregion
1
// regionand// endregionare not working with VS Code version 1.22 (haven't tested versions below or above that though). But// #regionand// #endregionworks (note the '#' and space in both). This way ESLint (if you are using) won't show error ifspaced-commentrule is on (i.e. not set to 'off' or 0).
– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually/* #region Foo Bar */and/* #endregion */
– toddmo
May 22 '18 at 1:18
At least in Python,# regionand# endregionwork if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie# region Example Heading.
– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
add a comment |
Code folding by regions has arrived with v1.17. Folding by regions documentation. And v1.19 and 1.23.
TypeScript/JavaScript: //#region and //#endregion and //region and //endregion
C#: #region and #endregion
C/C++: #pragma region and #pragma endregion
F#: //#region and //#endregion
PowerShell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
PHP: #region and #endregion
Bat: ::#region and ::#endregion
Each language also has snippets available for the markers. Type '#' and invoke code completion to see them. To have region markers configured for your language, contact the language extension provider.
v1.23 added CSS/SCSS/Less code folding regions:
CSS/SCSS/Less: /* #region */ and /* #endregion */ or /*#region*/ and /*#endregion*/
SCSS/Less: // #region and // #endregion
Code folding by regions has arrived with v1.17. Folding by regions documentation. And v1.19 and 1.23.
TypeScript/JavaScript: //#region and //#endregion and //region and //endregion
C#: #region and #endregion
C/C++: #pragma region and #pragma endregion
F#: //#region and //#endregion
PowerShell: #region and #endregion
Python: #region and #endregion
VB: #Region and #End Region
PHP: #region and #endregion
Bat: ::#region and ::#endregion
Each language also has snippets available for the markers. Type '#' and invoke code completion to see them. To have region markers configured for your language, contact the language extension provider.
v1.23 added CSS/SCSS/Less code folding regions:
CSS/SCSS/Less: /* #region */ and /* #endregion */ or /*#region*/ and /*#endregion*/
SCSS/Less: // #region and // #endregion
edited Dec 28 '18 at 4:07
answered Oct 6 '17 at 2:09
Mark
11.1k33349
11.1k33349
1
// regionand// endregionare not working with VS Code version 1.22 (haven't tested versions below or above that though). But// #regionand// #endregionworks (note the '#' and space in both). This way ESLint (if you are using) won't show error ifspaced-commentrule is on (i.e. not set to 'off' or 0).
– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually/* #region Foo Bar */and/* #endregion */
– toddmo
May 22 '18 at 1:18
At least in Python,# regionand# endregionwork if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie# region Example Heading.
– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
add a comment |
1
// regionand// endregionare not working with VS Code version 1.22 (haven't tested versions below or above that though). But// #regionand// #endregionworks (note the '#' and space in both). This way ESLint (if you are using) won't show error ifspaced-commentrule is on (i.e. not set to 'off' or 0).
– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually/* #region Foo Bar */and/* #endregion */
– toddmo
May 22 '18 at 1:18
At least in Python,# regionand# endregionwork if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie# region Example Heading.
– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
1
1
// region and // endregion are not working with VS Code version 1.22 (haven't tested versions below or above that though). But // #region and // #endregion works (note the '#' and space in both). This way ESLint (if you are using) won't show error if spaced-comment rule is on (i.e. not set to 'off' or 0).– ozanmuyes
Apr 11 '18 at 12:55
// region and // endregion are not working with VS Code version 1.22 (haven't tested versions below or above that though). But // #region and // #endregion works (note the '#' and space in both). This way ESLint (if you are using) won't show error if spaced-comment rule is on (i.e. not set to 'off' or 0).– ozanmuyes
Apr 11 '18 at 12:55
In CSS, it's actually
/* #region Foo Bar */ and /* #endregion */– toddmo
May 22 '18 at 1:18
In CSS, it's actually
/* #region Foo Bar */ and /* #endregion */– toddmo
May 22 '18 at 1:18
At least in Python,
# region and # endregion work if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie # region Example Heading.– Ian
Dec 13 '18 at 18:45
At least in Python,
# region and # endregion work if you want to avoid flake8 E265 or similar. Also, you can add text to label your regions, ie # region Example Heading.– Ian
Dec 13 '18 at 18:45
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
"Cold folding"? Do you mean "Code folding"?
– Peter Mortensen
Dec 15 '18 at 18:24
add a comment |
The default shortcut for collapse/extend are:
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + [ "Fold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Fold all"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + ] "Unfold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Unfold all"
Or go to keybindings.json and change as you wish.
For example:
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
,
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
,
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
Please review this:ctrl+shift+alt+[ "Unfold all"You wrote[instead of]. Correct me if I am wrong.
– fWd82
May 18 '17 at 7:50
add a comment |
The default shortcut for collapse/extend are:
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + [ "Fold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Fold all"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + ] "Unfold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Unfold all"
Or go to keybindings.json and change as you wish.
For example:
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
,
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
,
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
Please review this:ctrl+shift+alt+[ "Unfold all"You wrote[instead of]. Correct me if I am wrong.
– fWd82
May 18 '17 at 7:50
add a comment |
The default shortcut for collapse/extend are:
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + [ "Fold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Fold all"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + ] "Unfold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Unfold all"
Or go to keybindings.json and change as you wish.
For example:
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
,
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
,
The default shortcut for collapse/extend are:
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + [ "Fold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Fold all"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + ] "Unfold"
<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>[</kbd> "Unfold all"
Or go to keybindings.json and change as you wish.
For example:
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
,
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
,
edited Dec 15 '18 at 18:16
Peter Mortensen
13.5k1983111
13.5k1983111
answered Mar 29 '16 at 10:28
Samuel Pinto
71987
71987
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
Please review this:ctrl+shift+alt+[ "Unfold all"You wrote[instead of]. Correct me if I am wrong.
– fWd82
May 18 '17 at 7:50
add a comment |
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
Please review this:ctrl+shift+alt+[ "Unfold all"You wrote[instead of]. Correct me if I am wrong.
– fWd82
May 18 '17 at 7:50
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
is this limited to some languages? doesn't work for me on OSX/typescript.
– dcsan
Sep 3 '16 at 15:52
1
1
Please review this:
ctrl+shift+alt+[ "Unfold all"You wrote [ instead of ]. Correct me if I am wrong.– fWd82
May 18 '17 at 7:50
Please review this:
ctrl+shift+alt+[ "Unfold all"You wrote [ instead of ]. Correct me if I am wrong.– fWd82
May 18 '17 at 7:50
add a comment |
You should add user settings:
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
add a comment |
You should add user settings:
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
add a comment |
You should add user settings:
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
You should add user settings:
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
edited Apr 11 '18 at 14:10
answered Apr 11 '18 at 14:04
Minh Tien Tran
17615
17615
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
add a comment |
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
This is the answer I needed. By default, this setting is set to mouseover.
– Chim Chimz
Apr 19 '18 at 18:48
add a comment |
Collapsing is now supported in release 1.0:
Source Code Folding Shortcuts
There are new folding actions to collapse source code regions based on
their folding level.
There are actions to fold level 1 (Ctrl+K Ctrl+1) to level 5 (Ctrl+K
Ctrl+5). To unfold, use Unfold All (Ctrl+Shift+Alt+]).
The level folding actions do not apply to region containing the
current cursor.
I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. (Or two buttons left and one down starting from the backspace button.)
add a comment |
Collapsing is now supported in release 1.0:
Source Code Folding Shortcuts
There are new folding actions to collapse source code regions based on
their folding level.
There are actions to fold level 1 (Ctrl+K Ctrl+1) to level 5 (Ctrl+K
Ctrl+5). To unfold, use Unfold All (Ctrl+Shift+Alt+]).
The level folding actions do not apply to region containing the
current cursor.
I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. (Or two buttons left and one down starting from the backspace button.)
add a comment |
Collapsing is now supported in release 1.0:
Source Code Folding Shortcuts
There are new folding actions to collapse source code regions based on
their folding level.
There are actions to fold level 1 (Ctrl+K Ctrl+1) to level 5 (Ctrl+K
Ctrl+5). To unfold, use Unfold All (Ctrl+Shift+Alt+]).
The level folding actions do not apply to region containing the
current cursor.
I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. (Or two buttons left and one down starting from the backspace button.)
Collapsing is now supported in release 1.0:
Source Code Folding Shortcuts
There are new folding actions to collapse source code regions based on
their folding level.
There are actions to fold level 1 (Ctrl+K Ctrl+1) to level 5 (Ctrl+K
Ctrl+5). To unfold, use Unfold All (Ctrl+Shift+Alt+]).
The level folding actions do not apply to region containing the
current cursor.
I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. (Or two buttons left and one down starting from the backspace button.)
edited Dec 15 '18 at 18:17
Peter Mortensen
13.5k1983111
13.5k1983111
answered Apr 15 '16 at 7:21
Stian Standahl
1,47422137
1,47422137
add a comment |
add a comment |
If none of the shortcuts are working (like for me), as a workaround you can also open the command palette (Ctrl + 3 or View -> Command Palette...) and type in fold all:

add a comment |
If none of the shortcuts are working (like for me), as a workaround you can also open the command palette (Ctrl + 3 or View -> Command Palette...) and type in fold all:

add a comment |
If none of the shortcuts are working (like for me), as a workaround you can also open the command palette (Ctrl + 3 or View -> Command Palette...) and type in fold all:

If none of the shortcuts are working (like for me), as a workaround you can also open the command palette (Ctrl + 3 or View -> Command Palette...) and type in fold all:

answered Jun 8 '18 at 11:38
Jorn Vernee
19.9k33558
19.9k33558
add a comment |
add a comment |
As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient.
Any line followed by an indented line will have a '-' character to allow collapse. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block.
The (Ctrl + Shift + Alt + ]) will still affect all blocks, closing one level. Each repeated use closed one more level. The (Ctrl + Shift + Alt + [) works in the opposite way.
Hooray, block collapse finally works usefully.
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
add a comment |
As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient.
Any line followed by an indented line will have a '-' character to allow collapse. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block.
The (Ctrl + Shift + Alt + ]) will still affect all blocks, closing one level. Each repeated use closed one more level. The (Ctrl + Shift + Alt + [) works in the opposite way.
Hooray, block collapse finally works usefully.
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
add a comment |
As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient.
Any line followed by an indented line will have a '-' character to allow collapse. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block.
The (Ctrl + Shift + Alt + ]) will still affect all blocks, closing one level. Each repeated use closed one more level. The (Ctrl + Shift + Alt + [) works in the opposite way.
Hooray, block collapse finally works usefully.
As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient.
Any line followed by an indented line will have a '-' character to allow collapse. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block.
The (Ctrl + Shift + Alt + ]) will still affect all blocks, closing one level. Each repeated use closed one more level. The (Ctrl + Shift + Alt + [) works in the opposite way.
Hooray, block collapse finally works usefully.
edited Dec 15 '18 at 18:22
Peter Mortensen
13.5k1983111
13.5k1983111
answered Jul 16 '16 at 12:19
Miguelito
6319
6319
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
add a comment |
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
Adding to this - if you out-dent a comment around a region of code, you can use comments to build custom regions in your code and collapse entire custom segments! Great feature!
– Tim Cederquist
Jun 7 '17 at 16:40
add a comment |
With JavaScript:
//#region REGION_NAME
...code here
//#endregion
add a comment |
With JavaScript:
//#region REGION_NAME
...code here
//#endregion
add a comment |
With JavaScript:
//#region REGION_NAME
...code here
//#endregion
With JavaScript:
//#region REGION_NAME
...code here
//#endregion
edited Dec 15 '18 at 18:27
Peter Mortensen
13.5k1983111
13.5k1983111
answered Jan 19 '18 at 5:13
Rafael Grilli
444314
444314
add a comment |
add a comment |
On a Mac, it's the RHS Command key, ⌘K, not the left for the code folding commands.
Otherwise the left hand Command key will delete the current line, ⌘K.
add a comment |
On a Mac, it's the RHS Command key, ⌘K, not the left for the code folding commands.
Otherwise the left hand Command key will delete the current line, ⌘K.
add a comment |
On a Mac, it's the RHS Command key, ⌘K, not the left for the code folding commands.
Otherwise the left hand Command key will delete the current line, ⌘K.
On a Mac, it's the RHS Command key, ⌘K, not the left for the code folding commands.
Otherwise the left hand Command key will delete the current line, ⌘K.
edited Dec 15 '18 at 18:23
Peter Mortensen
13.5k1983111
13.5k1983111
answered Aug 17 '17 at 13:30
ReaddyEddy
18127
18127
add a comment |
add a comment |
This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.
Example:

add a comment |
This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.
Example:

add a comment |
This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.
Example:

This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.
Example:

edited Dec 15 '18 at 18:26
Peter Mortensen
13.5k1983111
13.5k1983111
answered Oct 29 '17 at 0:30
Murilo Perrone
493
493
add a comment |
add a comment |
I wish Visual Studio Code could handle:
#region Function Write-Log
Function Write-Log
...
#endregion Function Write-Log
Right now Visual Studio Code just ignores it and will not collapse it.
Meanwhile Notepad++ and PowerGUI handle this just fine.
Update: I just noticed an update for Visual Studio Code. This is now supported!
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
add a comment |
I wish Visual Studio Code could handle:
#region Function Write-Log
Function Write-Log
...
#endregion Function Write-Log
Right now Visual Studio Code just ignores it and will not collapse it.
Meanwhile Notepad++ and PowerGUI handle this just fine.
Update: I just noticed an update for Visual Studio Code. This is now supported!
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
add a comment |
I wish Visual Studio Code could handle:
#region Function Write-Log
Function Write-Log
...
#endregion Function Write-Log
Right now Visual Studio Code just ignores it and will not collapse it.
Meanwhile Notepad++ and PowerGUI handle this just fine.
Update: I just noticed an update for Visual Studio Code. This is now supported!
I wish Visual Studio Code could handle:
#region Function Write-Log
Function Write-Log
...
#endregion Function Write-Log
Right now Visual Studio Code just ignores it and will not collapse it.
Meanwhile Notepad++ and PowerGUI handle this just fine.
Update: I just noticed an update for Visual Studio Code. This is now supported!
edited Dec 15 '18 at 23:58
Peter Mortensen
13.5k1983111
13.5k1983111
answered Aug 7 '18 at 19:12
Mr. Annoyed
323112
323112
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
add a comment |
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
1
1
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
I really against regions. It's a serious smell if you really need them. Just make your code legible! I'm not telling you not to use them, cause that's your own choice. But consider reading up on the matter, before going all out on them. marcduerst.com/2016/10/03/c-regions-are-evil code-zest.blogspot.com/2014/05/region-hell-in-codebase.html Oh by the way "Uncle" Bob (still hate that name), also has a serious beef with them. twitter.com/unclebobmartin/status/7676319628 twitter.com/unclebobmartin/status/843943041954021377
– Saab
Aug 31 '18 at 7:32
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
@Saab I'd agree - you can do the same by pulling code out into smaller chunks. The tweets say: "In C#, regions are for hiding code you are ashamed of. Purge all regions!" and "I hate #regions. Code should not be hidden IMHO."
– Brian Burns
Nov 10 '18 at 12:34
add a comment |
In the windows build the shortcut is set to Alt + 0
add a comment |
In the windows build the shortcut is set to Alt + 0
add a comment |
In the windows build the shortcut is set to Alt + 0
In the windows build the shortcut is set to Alt + 0
answered Jan 2 at 23:42
SuperSandro2000
614
614
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30067767%2fhow-do-i-collapse-sections-of-code-in-visual-studio-code-for-windows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Does
#regionwork in Visual Studio Code? The code folding feature isn't supported, but maybe that's an alternative.– Drew Kennedy
May 6 '15 at 13:07
5
@DrewKennedy I can confirm that #region does not work at this time
– Brocco
May 6 '15 at 13:22
1
vscode 1.17 (September 2017) introduced region code.visualstudio.com/updates/v1_17#_folding-regions
– Bruno
Jun 10 '18 at 3:54