Recently I discovered that the little arrow next to lines in vscode, that allows you to fold parts of the code, had disappeared. I then noticed this was the case only in my Python files.
I scoped the internet looking for an answer, but nothing worked
I’v tried fixing the setting (by checking that the "folding" setting in the settings UI was ticked) but it did nothing, I tried removing the last extensions I had installed to see if they were interfering or something, but no.
Thanks for the info on #region, but even that doesn’t allow me to fold the code. I’ve tried with the command "fold" from the command palette and with ‘Ctrl+Shift+[‘ and ‘Ctrl+Shift+]’ but it didn’t work
I’m on Arch Linux using VsCode-OSS btw
4
Answers
Search folding in settings, and then check the first one.
You can also use the following code to test whether it is valid
For example:
Sort of expanding on the other answer, I’ve worked around it by changing settings for my python-specific workspace and changing the "Folding Strategy" to "indentation" instead of "auto", which seems to be a perfect workaround (for me at least) since Python requires proper indentation anyway and this doesn’t mess with global settings
image of the settings in question
I’m experiencing the exact same issue in VSCode on Windows (which is how I found this question) – only Python code folding seems to be broken, C++ etc seems to be fine, never noticed it happening before so I think a recent update broke it
If none of other answers helps you, you can create your custom folding range using
Ctrl+K Ctrl+,
on windows (I hope smth like that is in linux also, try searchingfolding range
). Selected lines willbe folded. To delete folding region, useCtrl+K Ctrl+.
.Just adding to what has been said above – with some visuals:
Select (bottom left): Manage > Settings > filter on folding
Then make sure
Editor: Folding
is checked and thatEditor: Folding Strategy
is set toindentation
– as belowFinally – close your session of VS Code
When you open VS Code again the folding settings should work.
Remember to mouseover to the left of
class
ordef
in your code to fold – as below: