SublimeText3 Fold/Unfold all methods

49,311

Solution 1

Using the Sublime Text 3 menu, you can find EDIT -> Code Folding -> which exposes the folding methods and will helpfully tell you the default keyboard shortcuts they are assigned to.

By default you press Ctrl+K, then Ctrl+1 to fold all subroutines. Then, to unfold all I would press Ctrl+K then Ctrl+J.

If this does not work for your file type / syntax, try Ctrl+K, Ctrl+2 and above to see if another folding level works for you.

Unfortunately for me, the proprietary code I work with required custom syntax and a custom function written in our in-house package to fold all of our functions (a new sublime command written in python and installed as a package).

Solution 2

More simple

Select the code and press:

Ctrl + Shift + [ to fold

Ctrl + Shift + ] to unfold


Updates

You can also select an element. Exemple:

enter image description here

Solution 3

Open the console (View -> Console or Ctrl`) with a source code file focused and enter the following commands at the bottom:

view.run_command("fold_all")
view.run_command("unfold_all")

to see their effect.

These commands can be bound with custom key bindings or put into the Command Palette for easy use.

Solution 4

Mac: Go to Edit/Code Folding as image bellow:

Details image

Share:
49,311
Scorb
Author by

Scorb

Updated on July 09, 2022

Comments

  • Scorb
    Scorb almost 2 years

    I am using SublimeText3 for C++ and Java. I am wondering if there is a way to fold all of the methods in a file / class, and then unfold them all, regardless of where the caret is. Or is there a way to list all the functions / methods.

    Basically I would like to be able to enter a file and see all the methods at one quick glance.

    Thanks

  • S.Yadav
    S.Yadav almost 5 years
    No need to select code, Ctrl + Shift + [ to fold and Ctrl + Shift + ] to unfold works in Sublime3, need to put cursor on the line which you want to fold.
  • rbz
    rbz almost 5 years
    @S.Yadav I tested on version 3.2.1 Build 3207. Really I can select an element and use as said. At the time I don't remember testing whether it worked or not, or if it was a release change. I made a complement in the answer. Thank you ✌️
  • Ghos3t
    Ghos3t over 4 years
    The Level 2 fold shortcut - Ctrl+K, Ctrl+2, works perfectly to fold all methods/functions in my Java code, in case anyone stumbles upon this post. Thanks Chris