Enabling Code Folding Bar in Xcode

4.6k views Asked by At

How to enable the code folding bar next to the line numbers?

I googled "code folding Mac"; it's all about triggering code folding and unfolding, but nothing about enabling the bar.

I have tried using Editor -> Code Folding -> Fold/Unfold to fold and unfold codes, but I don't have the vertical bar there next to the line numbers; so, I have the button to click to fold and unfold.

How can I enable that bar?

Please see image here here.

4

There are 4 answers

2
KarenAnne On BEST ANSWER

I always encounter this that suddenly I accidentally hide the Code folding ribon. So from @PetahChristian's answer, I captured it with screenshot.

Xcode > Settings > Text Editing > Check "Code Folding Ribbon"

You may also access Settings through shortcut command + ,

enter image description here

0
AudioBubble On

Go to Preferences -> Text Editing, and click Show code folding ribbon.

0
Krunal On

Code folding was disabled in Xcode 9 beta 1, which is working now, in Xcode 9 Beta5 according to beta release note: Resolved in Xcode 9 beta 5 – IDE

Here is how:

  1. Press and hold (command) button in keyboard and move/hover mouse cursor on any (start or end) braces. It will automatically highlight, block area.
  2. Keep (hold) (command) button in pressed condition and click on highlighted area. It will enable quick menu popover window with Fold option.
  3. Select Fold from menu list. It will fold your code and shows 3 dots, folding/covering entire block.
  4. Now, to again unfold your code block, release (command) button and click on 3 dots folding a block.

For easy understanding, look at this snapshot:

enter image description here


It's all keyboard short cuts are also working.

Fold                          ⌥ ⌘ ←      option + command + left arrow
Unfold                        ⌥ ⌘ →      option + command + right arrow
Unfold All                    ⌥ U        option + U
Fold Methods & Functions      ⌥ ⌘ ↑      option + command + up arrow
Unfold Methods & Functions    ⌥ ⌘ ↓      option + command + down arrow
Fold Comment Blocks           ⌃ ⇧ ⌘ ↑    control + shift + command + up
Unfold Comment Blocks         ⌃ ⇧ ⌘ ↓    control + shift + command + down
Focus Follows Selection       ⌃ ⌥ ⌘ F    control + option + command + F
Fold All                      ⌘ ⌥ ⇧ ←    command + option + shift + left
Unfold All                    ⌘ ⌥ ⇧ →    command + option + shift + left


Code folding options from Xcode Menu:

Menubar ► Editor ► Code Folding ► "Here is list of code folding options"

Here is ref snapshot:

enter image description here

Same options from Xcode Short-cut list:

Menubar ► Xcode ► Preferences ► Key Bindings ► "Here is list of code folding short-keys"

enter image description here

0
Deepak Chaudhary On

Updated Answer for Xcode 12 and above Code folding ribbon is quite useful and easy to view code scope.

Go to Preferences -> Text Editing -> Display, and click on Code folding ribbon

enter image description here