Xcode: how to see matching brace?

Every IDE I have ever used (besides XCode) has a dead-simple way for you to find the matching brace in a piece of code. You usually select one brace and then the other one is highlighted.


XCode does this but only for like 1/100000 of a second, and it does not help when the brace is off the screen, which is the only time you really need this function.


Is there a way to do it? I know there used to be that way of folding up the entire scope so that it disappeared, but I always hated that, it was confusing and alarming, and besides I don't even see it anymore.


Can somebody please let me know how to do it? I am sure there is a way and I don't see it -- why don't they just do it like everyone else does?

Accepted Answer

Xcode highlights an opening delimiter (brace, bracket, parenthesis) when you move the cursor left-to-right over the matching closing delimiter. The highlight animation lasts about 1 second total, which is plenty in the case where you need a hint (and as you say the other delimiter is nearby).


If you need a more persistent indication, you can double-click either the opening or the closing delmiter, and Xcode will select both delimiters and their contents. (You can also use this, for example, to get quickly to one delimiter from another, even if they're far apart — double-click the delimiter you can see, use the left or right arrow to get the the other end of the selection.)


Presumably, they don't "just do it like everyone else does" because Xcode has done it this way for many, many years and people who actually use Xcode are used to it and would prefer that it wasn't arbitrarily changed on them.


C# (for example) has a non-selection highlighting mechanism that's useful, but it also results in your source code lighting up, sometimes, in a chaos of garish colors. So it's pretty much a personal choice which unpleasant side effects you prefer.


Still, this is the sort of thing you should submit a bug report about, since that's how the popularity contest for new features works. If enough people ask for it, Apple may well change or enhance the current behavior.

Answers

Xcode highlights an opening delimiter (brace, bracket, parenthesis) when you move the cursor left-to-right over the matching closing delimiter. The highlight animation lasts about 1 second total, which is plenty in the case where you need a hint (and as you say the other delimiter is nearby).


If you need a more persistent indication, you can double-click either the opening or the closing delmiter, and Xcode will select both delimiters and their contents. (You can also use this, for example, to get quickly to one delimiter from another, even if they're far apart — double-click the delimiter you can see, use the left or right arrow to get the the other end of the selection.)


Presumably, they don't "just do it like everyone else does" because Xcode has done it this way for many, many years and people who actually use Xcode are used to it and would prefer that it wasn't arbitrarily changed on them.


C# (for example) has a non-selection highlighting mechanism that's useful, but it also results in your source code lighting up, sometimes, in a chaos of garish colors. So it's pretty much a personal choice which unpleasant side effects you prefer.


Still, this is the sort of thing you should submit a bug report about, since that's how the popularity contest for new features works. If enough people ask for it, Apple may well change or enhance the current behavior.

Thanks! While I think this is a rare instance of everyone else doing it better than Apple, just knowing how to do it is really all I need. I've been using XCode as long as it's been around and never have known that double-click thing. It never bothered me until recently, when I have been using both VS 2013 and GameMaker and have begun to appreciate just putting the cursor on a brace and having the other one light up (for more than a second).

Do all the developer in Apple write functions shortly like that?

So, Their functions can be shown up in one page of their monitor?

And!!

Double-Click?? I cannot write codes using my mouse.

Should I move my right hand to the mouse when I wanna just check the brace??

I think they must make another way....

Ah! I had forgotten how to do this, again! Why doesn't Apple just do it the sensible way like every other IDE in existence...

As the correct answer states: "people who actually use Xcode are used to it and would prefer that it wasn't arbitrarily changed on them." so you must just be a person who doesn't "actually use XCode"...

I prefer your earlier answer, it was more accurate 🙂

Don't want my account to be banned, I got clients, probably still ain't a person who "actually uses XCode" ^^

Blessed be the fruit

just noticed that when I copy text from a different post into the answer here, everytime I type into this comment field after that, the page scrolls up to the top. I'm on a mac even.... Apples developers must be the best in the world. Can you reproduce this?

No I don't think so -- that seems work ok for me.

Hmmm happens in Chrome though, and only on MacOS

Double-clicking on the curly brace not only highlights the block but also jumps to the start (or end) of the block. So it is like the keyboard short cuts most IDEs provide except that it is a mouse double-click not a key press. I don't see any reason why they couldn't add a keyboard shortcut for it as well though.
Another case of XCode doing things differently to most other IDEs is getting to the start or end of the file. It took me ages to find out how to do this in XCode without needing to drag the scroll bar with the mouse. The XCode short-cuts are Command-up, and Command-down. (Ctrl-PageUp and Ctrl-PageDown would make more sense to me).
It would be really nice if Apple at least tried to make life a bit easier for developers who also use popular IDEs like Visual Studio and Intelli J.

I don't think there is a way to do this.