I’m new to Python, and I’m trying to fold my code in a way that’s similar to regular Visual Studio with C#.
In VS, you can press Ctrl+M, O
to fold all methods and #regions
, and then press Ctrl+M, P
to unfold.
VS Code has a similar feature with Ctrl+K, 0
and Ctrl+K, J
. However, this feature folds a lot of the contents of the functions, like if/else statements.
2
Answers
If you are familiar with #region you can still use this tag in vscode.
You could add
#region
and#endregion
before and after the code that needs to be folder, such as:You can manually click on the arrows, or use the shortcuts ctr+8 and ctrl+9 to collapse or expand.
From what I understand, you want to collapse to definitions, i.e., only 1 level? Assuming you are on Windows/Linux as you use Ctrl:
Fold Level 1
Unfold all
You can specify depth of folding by changing the number after
Ctrl+K
.