In Sublime Text, how can I specify the fold level, with keyboard shortcuts, without having to unfold all first?

Posted on

QUESTION :

I’m trying to work out how to get code folding working how I want in Sublime Text 2.

I can +K, +J to unfold all.
Then I can do +K, +1 to fold all.

At this point, I want to be able to go straight to fold level x (i.e. fold level 2). But if I do +K, +2, nothing happens.

To get to fold level 2, I first have to unfold all, then do +K, +2.

How can I specify the fold level, with keyboard shortcuts, without having to unfold all first?

ANSWER :

In your sublime text keymap, add:

{ "keys": ["ctrl+1"], "command": "fold_by_level", "args": {"level": 1} },
{ "keys": ["ctrl+2"], "command": "fold_by_level", "args": {"level": 2} },
{ "keys": ["ctrl+3"], "command": "fold_by_level", "args": {"level": 3} },
{ "keys": ["ctrl+4"], "command": "fold_by_level", "args": {"level": 4} },
{ "keys": ["ctrl+5"], "command": "fold_by_level", "args": {"level": 5} },
{ "keys": ["ctrl+6"], "command": "fold_by_level", "args": {"level": 6} },
{ "keys": ["ctrl+7"], "command": "fold_by_level", "args": {"level": 7} },
{ "keys": ["ctrl+8"], "command": "fold_by_level", "args": {"level": 8} },
{ "keys": ["ctrl+9"], "command": "fold_by_level", "args": {"level": 9} },

Level 1 is fold all. Match the “,” in your JSON to work. Done. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *