There’s no direct setting built into Sublime to do this without a little bit of extra work, but it doesn’t take much to set it up.
Presuming that using Edit > Code Folding > Fold All
folds the document the way you want it to be, you can use a simple plugin that executes that command on any file that happens to be loaded (see here if you don’t know how to use plugins in Sublime):
import sublime
import sublime_plugin
class FoldingEventListener(sublime_plugin.EventListener):
def on_load(self, view):
view.run_command("fold_by_level", {"level": 1})
Here every time a file is initially loaded, the fold_by_level
command is executed to fold everything at level 1 and beyond, which corresponds to the menu item above. The level could be changed if one of the other default folding items is more preferable.
Written this way, this will trigger on any file that you happen to open, which may or may not be desirable. In that case the code would need to be tweaked a little bit to have it only take effect in files of certain types.
There may or may not be a package on Package Control that implements something like this on it’s own, but I’m not aware of any personally.
An alternative might be something like AutoFoldCode; according to the README it doesn’t fold files on the first load but it will remember and re-apply the fold state when you close and later re-open a file. So possibly you could set up a key binding to the above fold_by_level
command to fold everything manually and use that package to remember the state for later, or something similar.