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

前端 未结 16 1175
后悔当初
后悔当初 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:37

    Now with xCode 8 you can do:

    + + /

    to auto-generate a doc comment.

    Source: https://twitter.com/felix_schwarz/status/774166330161233920

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

    In XCode 10 (and up) use Option + Command + Slash (that is ⌥ + ⌘ + /)

    to write a beautiful comment for your function or class like below:

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

    Try command + /. It works for me.

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

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

    i managed to get this working well via an automator task and have used shortcut to bind it to key combination ctrl+option+command+b. all i have to do is highlight the code i want block commented in xcode and press the above keys and the selected text is block commented out using /* ... */.

    i use code folding a fair bit so the reason i wanted this functionality was so i could easily fold down a block of commented code ... code commented the usual way using // wont fold.

    im not familiar with using mac automator but i simply followed the instrux in the following wwdc video

    in the WWDC 2012 video Session 402 - Working Efficiently with Xcode ( from around 6 minutes in) there's a description of how to use the Mac OSX Automator to add a service to manipulate selected text. The example shown in the video is to remove duplicates in a selection of text using the shell commands sort and uniq. Using this approach you do the same but you enter the following command instead of what he does in the video

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

    (note there are meant to be 2 asterisks in the previous line that for some reason are not showing .... they do show up in the screenshot below so copy that as the correct command to enter)

    you should end up running a shell script like this

    screenshot

    this will, for any given selected text, put the comment delimiters before and after.

    when you save it you should get options to name it (i called it blockcomment) and also to assign a keyboard shortcut

    then you should be able to open xcode, select some text, right click, the context menu, and the name you gave to this script should show near the bottom

    simply click the name and the script will run and block comment the selected code or use the keyboard shortcut you assigned.

    hope this helps

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