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

1

1

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?

ben

Posted 2014-04-12T21:49:48.727

Reputation: 93

This guide should be helpful for you.

– Anton Dozortsev – 2014-04-13T08:37:11.220

Answers

1

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. ;)

VIPRYN

Posted 2014-04-12T21:49:48.727

Reputation: 11