Xcode Command-Slash Shortcut to Comment Only Works Sometimes

33,101

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:

  1. Close Xcode
  2. In the Application folder, rename Xcode.app (or similar) to Xcode2.app. You might need to type in your password.
  3. Open Xcode, then close it.
  4. Rename Xcode2.app back to what it was before.
  5. (Optional) Spend 5 minutes wondering why this worked.

No need to reboot!

Share:
33,101
Stonz2
Author by

Stonz2

Updated on July 10, 2022

Comments

  • Stonz2
    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
    ZeMoon over 8 years
    I visited this answer once for Xcode 6 and now had to do the same for Xcode 7.
  • atulkhatri
    atulkhatri over 8 years
    Seems Apple is not interested in fixing this minor bug ;) Glad it helped again.
  • Septronic
    Septronic over 8 years
    Fantastic! this bugged me for so long, and now it's a thing of the past :) thank you
  • CryingHippo
    CryingHippo over 7 years
    I believe it recreates cache for Xcode source editor extensions
  • ShujatAli
    ShujatAli over 7 years
    Its not working again on xcode 8, and above answer didn't helped me :(
  • Szu
    Szu over 7 years
    Does restart Mac was the only thing to do?
  • simioliolio
    simioliolio over 7 years
    Did not work for me with Xcode 8.0. Loved this shortcut.
  • xcvr
    xcvr over 7 years
    Xcode 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 to Xcode.app fixed it for me. Thanks!
  • Naishta
    Naishta over 7 years
    Awesome dude, saved me from restart !
  • Roman Truba
    Roman Truba over 7 years
    @simioliolio did you restart?
  • T'Pol
    T'Pol over 7 years
    Yes, restart is necessary (unfortunately...)
  • turingtested
    turingtested over 7 years
    Happened just now for me on Xcode 8.1 - and this solution still works. Restart needed only for Xcode, not the computer.
  • Florin
    Florin over 7 years
    Worked 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
    dahiya_boy over 7 years
    I 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
    Sam over 7 years
    don'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
    pkamb over 7 years
    "and restart your computer" is not an acceptable solution, Apple :/
  • Bot
    Bot over 7 years
    This seems to only work temporarily. As the next day I have to redo this same command, every day.
  • HRoot
    HRoot about 7 years
    This did just help me on XCode 8.2.1, for what its worth, so thanks :)
  • Jim Leask
    Jim Leask about 7 years
    Please 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
    Zoltán about 7 years
    Funny how crazy/creative you have to get to fix this little annoyance.
  • ecotax
    ecotax about 7 years
    Given 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
    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
    luisdemarchi almost 7 years
    Worked for 8.3.3 [2]
  • Kqtr
    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
    souvickcse over 6 years
    u r genius awesome
  • Kqtr
    Kqtr over 6 years
    Feels great to look again for the solution to this problem a month later and find my own answer here! :D Still works folks.
  • jeremyabannister
    jeremyabannister over 6 years
    Worked for me on 8.3
  • Hernan Arber
    Hernan Arber over 6 years
    Works! Thanks :-D
  • Aleksandar
    Aleksandar about 6 years
    Works 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
    DatForis over 5 years
    Worked on Xcode 9.4. I can't believe they still haven't fixed this
  • Meshach
    Meshach over 5 years
    Yep, had the same issue and just rebooted, worked great.
  • CodeBender
    CodeBender over 5 years
    Worked on 10.1 as well. Above answers did not.
  • spnkr
    spnkr about 5 years
    thanks! this fixed it for me. i'm running mac os mojave 10.14.4.
  • Wendy Liga
    Wendy Liga about 5 years
    worked on 10.2 , i have multiple xcode setup before
  • ll_cool_aid
    ll_cool_aid about 4 years
    Its a shame we still have this issues on Xcode 11.3.1, yet again this solution worked.
  • Tul
    Tul almost 3 years
    Worked like a charm for me as well on Xcode 12.5.1! Thanks dude!
  • lorenzo
    lorenzo over 2 years
    I experience the problem in Xcode 13 / MBP 2021, this works for me temporarily but the issue comes back regularly