Sublime Forum

Code folding in Sublime Text


I am using Sublime Text 3.2.2 for writing Python scripts.
Sublime automatically adds a fold/unfold block when detecting commands like:


I´d like to override this behaviour and define my own set of characters for folding/unfolding.
Exactly, I want #+ to indicate the beginning of a folding block and #- to indicate the end.

Is there a (not to complicated) way of achieving this in this editor?

Many thanks.



Code folding in Sublime is currently based off of the indentation of files;; it only appears to indent on keywords like the ones you mentioned above because they contain indented code.

It’s not currently possible to override that at the moment but the options in the Edit > Code Folding menu or the key bindings for those commands (visible from the menu) can also be used for folding, and the first one will fold the current selection. That can be useful when combined with the items from the Selection menu.



Oh, I see.
That´s a pity.
It would be great if they implement it in the future.
In terms of organizing the scripts, I think it is important to be able to control the fold/unfold.
In SciT4AutoHotkey (other script editor) it is possible to define which character or string of characters indicate a folder opening or close, and I find it really useful.

Many thanks for your quick answer.



I havent added fold markers but I know there is a package that does something like what you describe.

I have however taken control of the folding behaviour entirely. OrgExtended allows you to fold lots of things using the tab key and has fold cycling. I just manually manage the folds myself in the package. The gif on my package page shows the fold cycling using tab.



I cant find the other package now.
Thought it might be auto fold or attr fold. I ran across it a while ago. Allowed you to define custom fold markers



Ah here it is:



Many thanks.
I´ll give it a try.

1 Like