Is there a shortcut to make a block comment in Xcode?

163

I'm writing ANSI-compatible C code, and hence I can't use the line (//) comment. I'm using Xcode. In Sublime Text and Eclipse, and I think most other IDEs, there are separate keyboard shortcuts for line comments and block comments (/**/). However, I don't see that in Xcode - in fact, I don't even see a menu option to add a block comment. Is it simply not supported in Xcode? That would certainly seem to be a lame decision if so.

This question is tagged with xcode comments

~ Asked on 2012-11-03 18:41:31

The Best Answer is


248

Try command + /. It works for me.

So, you just highlight the block of code you want to comment out and press those two keys.

~ Answered on 2013-04-16 14:10:59


43

UPDATE:

Since I was lazy, and didn't fully implement my solution, I searched around and found BlockComment for Xcode, a recently released plugin (June 2017). Don't bother with my solution, this plugin works beautifully, and I highly recommend it.

ORIGINAL ANSWER:

None of the above worked for me on Xcode 7 and 8, so I:

  1. Created Automator service using AppleScript
  2. Make sure "Output replaces selected text" is checked
  3. Enter the following code:

    on run {input, parameters}
    return "/*\n" & (input as string) & "*/"
    end run
    

enter image description here

Now you can access that service through Xcode - Services menu, or by right clicking on the selected block of code you wish to comment, or giving it a shortcut under System Preferences.

~ Answered on 2016-08-15 13:40:40


Most Viewed Questions: