Sublime Forum

Help with broken / changed code folding in C#


Hi all,

So, I’ve noticed in the last year something changed in sublime text and C# code folding has broken ( or changed) to the point that it only seems to work with wrapping methods directly.

I became accustomed to code folding #region code as well as custom “/// —>” lines which really helped to clean up my code. This has become second nature to me after working with sublime text for many years and I would like to get them working again. BTW: the old code-folding approaches actually still work if I set the file type from C# to “Plain Text” in the bottom right of the sublime text window, but then I obviously lose color syntax which is even worse.

So the short question is, is there any way to use C# color syntax with the code-folding functionality of “Plain Text” ( as that seems to work fine ).

Any help would be much appreciated!


EDIT: Replaced “Code-wrapping” to “code-folding”.



Word wrap has always been disabled for source scope, while being enabled in text.

The behavior is controlled by "word_wrap": "auto", setting.

To enable word wrapping in C# you probably want to set "word_wrap": true, in syntax-specific settings.



Hi @deathaxe

Appreciate the reply. To clarify, I am not talking about word wrapping but rather “code wrapping”. When you can wrap blocks of code with the little arrows next to the line numbers on the left.

I’m assuming that’s a different setting?



You mean code folding?



Yep - my apologies :slight_smile:

(EDIT: Updated thread title )



ST4143+ supports syntax based code folding.

C# has been configured to use syntax based folding, with the assumption it beeing the more appropriate approach.

Feedback from various users revealed disabling indentation based folding is unfortune depending on various code styles and workflows.

Unfortunatelly a general PR to revert that change has more or less been rejected (see:

You have 2 options to re-enable it:

  1. Create an override for Packages/C#/Fold.tmPreferences with the related line removed

    This way both engines would do their job next to each other. I personally like the way how braces are folded by syntax based folding.

  2. Set "fold_style": "force_indentation" in syntax specific settings or global Preferences to revert to old ST3 behaviour.



Hi @deathaxe,

Thanks for the info! Much appreciated.

I just tried 2 ( as it seemed to be the easiest fix ) but that doesn’t seem to change how the code folding is working for me - unless I’m missing something obvious?

Steps I took:
went to Settings… > Settings - Syntax Specific

The whole thing on the right looks like this:

// These settings override both User and Default settings for the C# syntax
“fold_style”: “force_indentation”



I missed to say the setting is supported as of ST4145+. So if you are still on stable channel (ST4143), option 1) is the only one available.



Hi @deathaxe,

Just downloaded the dev build and it works!

Thanks a lot for providing the solution - I know it’s probably a personal preference thing, but it was really making me consider switching away from Sublime because it was annoying me so much, haha.

Happy that I don’t need to do that anymore! :slight_smile:

Thanks again!

1 Like