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

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.


Try command + /. It works for me.

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


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:

  • Created Automator service using AppleScript
  • Make sure "Output replaces selected text" is checked
  • Enter the following code:

    on run {input, parameters}
    return "/*n" & (input as string) & "*/"
    end run
    
  • 在这里输入图像描述

    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.


    There is now an Xcode plugin that allows this: CComment.

    The easiest way to install this is to use the amazing Alcatraz plugin manager for Xcode.

    EDIT Apple has sadly (and wrongly, IMHO) retired the old plugin model with Xcode 8. The new plugin system is quite limited, but should allow development of a plugin like this again. For anyone interested in doing this, watch WWDC 2016 session 414. Also, please file radars for API for plugins you'd like to write or see.

    链接地址: http://www.djcxy.com/p/14944.html

    上一篇: 在build.gradle文件中写评论的语法是什么?

    下一篇: 是否有快捷方式在Xcode中创建块注释?