skip to Main Content

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


  1. enter image description here

    Search folding in settings, and then check the first one.

    You can also use the following code to test whether it is valid

    # region
    
    # endregion
    

    For example:

    # region hi
    print("HelloWorld")
    # endregion
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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 searching folding range). Selected lines willbe folded. To delete folding region, use Ctrl+K Ctrl+..

    Login or Signup to reply.
  4. 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 that Editor: Folding Strategy is set to indentation – as below

    enter image description here

    Finally – 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 or def in your code to fold – as below:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search