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

前端 未结 16 1173
后悔当初
后悔当初 2020-11-30 18:57

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, t

相关标签:
16条回答
  • 2020-11-30 19:15

    in Macbooks, you can use shift + cmd + 7 to comment a previously highlighted block

    0 讨论(0)
  • 2020-11-30 19:15

    Seems like already a lot of people answers this question.

    in Swift 3.0, single line comment is to put double forward slashes upfront : "//" ; multiline is put "/* .... */".

    Hope this helps.

    0 讨论(0)
  • 2020-11-30 19:17

    I modified the code of Nikola Milicevic a little bit so it also remove comment block if code is already commented:

    on run {input, parameters}
        repeat with anInput in input
            if "/*" is in anInput then
                set input to replaceText("/*", "", input as string)
                set input to replaceText("*/", "", input as string)
    
                return input
                exit repeat
            end if
        end repeat
        return "/*" & (input as string) & "*/"
    end run
    
    on replaceText(find, replace, textString)
        set prevTIDs to AppleScript's text item delimiters
        set AppleScript's text item delimiters to find
        set textString to text items of textString
        set AppleScript's text item delimiters to replace
        set textString to "" & textString
        set AppleScript's text item delimiters to prevTIDs
        return textString
    end replaceText
    

    Hope this will help someone.

    0 讨论(0)
  • 2020-11-30 19:17

    Cmd + Shift + 7 will comment the selected lines.

    0 讨论(0)
  • 2020-11-30 19:20

    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.

    0 讨论(0)
  • 2020-11-30 19:23

    UPDATE: Xcode 8 Update

    Now with xcode 8 you can do:

    + + /

    Note: Below method will not work in xcode version => 8

    Very simple steps to add Block Comment functionality to any editor of mac OS X

    1. Open Automator
    2. Choose Services
    3. Search Run Shell Script and double click it

    Add the below applescript in textarea

    awk 'BEGIN{print "/*"}{print $0}END{print "*/"}'

    1. Save script as Block Comment

    Add a keyboard shortcut

    Open System Preference > Keyboard > Shortcuts, add new shortcut by clicking + and right the same name i.e. Block Comment as you given to applescript in the 4th step. Add your Keyboard Shortcut and click Add button.

    Now you should be able to use block comment in Xcode or any other editor, select some text, use your shortcut key to block comment any line of code or right click, the context menu, and the name you gave to this script should show near the bottom.

    0 讨论(0)
提交回复
热议问题