Xcode Command-Slash Shortcut to Comment Only Works Sometimes
Solution 1
For an Xcode 8, solution is
sudo /usr/libexec/xpccachectl
and restart your computer.
Solution 2
Hit ⌘+] once and then ⌘+/ will start working again.
You can hit ⌘+[ to undo the indentation effect.
Update:
Please note- This solution was provided prior to Xcode 8 launch so it may not work for everyone. If you are still facing problem, kindly refer to @CryingHippo's answer instead of downvoting.
Solution 3
I have done this numerous times with Xcode 8. Latest being Xcode 10.1 where I would just quit Xcode and go to Applications and rename Xcode to something else, e.g. Xcode 2, launch it, quit again and rename back. It starts working after that. No Mac restart or Terminal commands required.
It still works as of Xcode 10.1. I cannot believe Apple still hasn't fixed it properly.
Solution 4
None of the above solutions worked for me with Xcode 8.0 (final). If you also have Xcode 8.1 beta installed like I do, try this: simply rename /Applications/Xcode-beta.app to something else, then restart Xcode 8. Oddly enough, that did the trick.
Solution 5
Oscahie's answer actually works for non-beta versions of Xcode as well. Here are the steps to follow, based on Sam's comment:
- Close Xcode
- In the Application folder, rename Xcode.app (or similar) to Xcode2.app. You might need to type in your password.
- Open Xcode, then close it.
- Rename Xcode2.app back to what it was before.
- (Optional) Spend 5 minutes wondering why this worked.
No need to reboot!
Stonz2
Updated on July 10, 2022Comments
-
Stonz2 almost 2 years
I'm having issues with Xcode being quite unreliable when using the keyboard shortcut to comment or uncomment code ⌘+/. I can't seem to find a real pattern as to when it breaks, but it usually happens after building and running my code on the simulator. It will not work again until I edit something in any one of my code files. Even if I switch to another file in the main view, commenting via shortcut does not work. Other keyboard shortcuts, such as indenting ⌘+[ continue to work just fine.
Do other people have this issue, and if so, have you found a solution? I know it seems like a small complaint, but when running and then quickly trying to comment out a block of code to check the effect, it's a bit of an inconvenience.
I am using Xcode 6.1 (6A1052d) on OXS Yosemite 10.10 (14A389) and developing in Objective-C for iOS if that matters.
-
ZeMoon over 8 yearsI visited this answer once for Xcode 6 and now had to do the same for Xcode 7.
-
atulkhatri over 8 yearsSeems Apple is not interested in fixing this minor bug ;) Glad it helped again.
-
Septronic over 8 yearsFantastic! this bugged me for so long, and now it's a thing of the past :) thank you
-
CryingHippo over 7 yearsI believe it recreates cache for Xcode source editor extensions
-
ShujatAli over 7 yearsIts not working again on xcode 8, and above answer didn't helped me :(
-
Szu over 7 yearsDoes restart Mac was the only thing to do?
-
simioliolio over 7 yearsDid not work for me with Xcode 8.0. Loved this shortcut.
-
xcvr over 7 yearsXcode 8: I didn't have the beta installed (but have had betas in the past). Renaming
Xcode.app
to something else, relaunching, quiting, then renaming it back toXcode.app
fixed it for me. Thanks! -
Naishta over 7 yearsAwesome dude, saved me from restart !
-
Roman Truba over 7 years@simioliolio did you restart?
-
T'Pol over 7 yearsYes, restart is necessary (unfortunately...)
-
turingtested over 7 yearsHappened just now for me on Xcode 8.1 - and this solution still works. Restart needed only for Xcode, not the computer.
-
Florin over 7 yearsWorked for me. But these kind of hacks are unacceptable. XCode 8 is broken in many areas - for example, C++ editing is a disaster - even syntax highlighting doesn't work most of the times. Apple, get your shit together. Maybe stop rushing a buggy new OS every half a year and focus on increasing quality.
-
dahiya_boy over 7 yearsI followed this steps and restart my system and even x-code too but it doesn't work for me. Is there any other trick to re-solve this problem. I have x-code 8.x and El-captain OS.
-
Sam over 7 yearsdon't know why the heck this worked, but it did. (1) renamed to Xcode8.app. (2) opened Xcode. (3) closed Xcode. (4) renamed back to what it was before (Xcode8.0.app). the nice thing about this answer is that it doesn't require machine restart!
-
pkamb over 7 years"and restart your computer" is not an acceptable solution, Apple :/
-
Bot over 7 yearsThis seems to only work temporarily. As the next day I have to redo this same command, every day.
-
HRoot about 7 yearsThis did just help me on XCode 8.2.1, for what its worth, so thanks :)
-
Jim Leask about 7 yearsPlease answer what the command does if you can. I haven't been able to find docs for it, and don't really like running commands blind.
-
Zoltán about 7 yearsFunny how crazy/creative you have to get to fix this little annoyance.
-
ecotax about 7 yearsGiven the may upvotes I'm convinced this works in most cases - but not all. This problem has several duplicates, and in one of them I read that this feature can relatively easily get confused by nested comments like /* // */, or (as was the case with me) by text that's not even comment according to the C++ parser doesn't see as comment at all because it was in a string, like std::make_pair(true, "/*//*/")
-
atulkhatri almost 7 years@coolcool1994 Like mentioned in the answer itself, this may or may not work depending upon your XCode version. Please do not down vote. Thanks.
-
luisdemarchi almost 7 yearsWorked for 8.3.3 [2]
-
Kqtr almost 7 years@Sam thanks, this worked for me as well, will suggest an edit to oscahie's answer, as it works for non-beta too
-
souvickcse over 6 yearsu r genius awesome
-
Kqtr over 6 yearsFeels great to look again for the solution to this problem a month later and find my own answer here! :D Still works folks.
-
jeremyabannister over 6 yearsWorked for me on 8.3
-
Hernan Arber over 6 yearsWorks! Thanks :-D
-
Aleksandar about 6 yearsWorks on Xcode 9 as well. So disappointed for the fact that this has not been resolved by Apple for so many versions of Xcode... :(
-
DatForis over 5 yearsWorked on Xcode 9.4. I can't believe they still haven't fixed this
-
Meshach over 5 yearsYep, had the same issue and just rebooted, worked great.
-
CodeBender over 5 yearsWorked on 10.1 as well. Above answers did not.
-
spnkr about 5 yearsthanks! this fixed it for me. i'm running mac os mojave 10.14.4.
-
Wendy Liga about 5 yearsworked on 10.2 , i have multiple xcode setup before
-
ll_cool_aid about 4 yearsIts a shame we still have this issues on Xcode 11.3.1, yet again this solution worked.
-
Tul almost 3 yearsWorked like a charm for me as well on Xcode 12.5.1! Thanks dude!
-
lorenzo over 2 yearsI experience the problem in Xcode 13 / MBP 2021, this works for me temporarily but the issue comes back regularly