Fold / Collapse the except code section in sublime text 2

Sublimetext2Sublimetext3

Sublimetext2 Problem Overview


Is there any plugin or shortcut to hide all except code section in sublime text 2?

I need to fold all except section at a time , Not fold one section at a time.

Thanks~

enter image description here

Sublimetext2 Solutions


Solution 1 - Sublimetext2

If you'll hover with the mouse over the line numbers you'll see arrows - clicking on any of them will fold/collapse the code

enter image description here

enter image description here

If you want to collapse/expand all - you can do so by going to edit->code folding and choose "fold all" or "unfold all":

enter image description here

Solution 2 - Sublimetext2

In addition to the other answers it is also possible to fold based on level as well. So for example looking at the default key bindings for fold.

Subblime key bindings default

Searching for fold key bindings.

searching for fold key bindings in sublime

So for example a foldall, or folding level 1 would be to hold Ctrl followed by pressing the sequence k and then 1:

enter image description here

Or folding level 2 would be to hold Ctrl followed by pressing the sequence k and then 2:

enter image description here

Or unfolding all would be would be to hold Ctrl followed by pressing the sequence k and then 0 or in my defaults I also seem to have it bound to the letter j:

enter image description here

Warning.

Pressing Ctrl+k twice will remove a line or a count of lines. But not really cause you can put them back one by one by Ctrl+u

Solution 3 - Sublimetext2

One thing you can do is select the Except code bloc using a regular expression, for instance using except(.|\n)*?raise.* in your case. You can then select "Find all" in the search bar, then Edit->Code Folding -> Fold .
Windows shortcut : Ctrl-Shift-[
Mac shortcut: Cmd-Alt-[

All the Except bloc will then be collapsed.

Solution 4 - Sublimetext2

I know this is an old question, but it still comes up high in search results and none of the answers quite do what the OP wanted.

  1. select the code you don't want to be hidden
  2. use "Selection" -> "Invert Selection" to select the code you do want to be hidden instead
  3. use ctrl + shift + [ or Command + Option + ] to collapse the selection(s)

This will leave you with just the code you originally had selected visible.

Solution 5 - Sublimetext2

Fold and UnFold function or class base only for MAC:

 * Fold: command + K, command + 1
 * UnFold: command + K, command + J

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnewBikeView Question on Stackoverflow
Solution 1 - Sublimetext2Nir AlfasiView Answer on Stackoverflow
Solution 2 - Sublimetext2jmunschView Answer on Stackoverflow
Solution 3 - Sublimetext2LiteralView Answer on Stackoverflow
Solution 4 - Sublimetext2Jon GreenView Answer on Stackoverflow
Solution 5 - Sublimetext2Govind SharmaView Answer on Stackoverflow