Keybind to fold function or class in Sublime?

1.8k Views Asked by At

Is there a keybind to press the little fold arrow that appears before a function or class?

enter image description here

3

There are 3 best solutions below

2
On

Goto EDIT > Code Folding. It will show you all the command for Sublime Text.

0
On

I don't think there is. What you can do though is this:

def my_func():
     # put your cursor wherever you want on a line that has this level of indentation (here 1)
    """my doc"""
    print('this is') # you can put it here
    print('some code that is going to') # or here
    print('folded!')
    if nb % 2 == 0:
        print('this is an even number') # but not here!

press ctrl+shift+[. It going to automatically select the indentation (so your function's content), and fold it up.

0
On

Similar to @math2001's answer, ctrl+shift+l will fold a class or function

This only works when the cursor is below the indentation you want to fold.

Ie. you want to fold functionB, the cursor must be on a line above or below functionB's braces

functionA() {
    functionB() { //I will fold under A. Don't fold here
        //Fold me
        functionC() { //Fold me
        } //Fold me
    } //Fold me
}