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
in Macbooks, you can use shift + cmd + 7 to comment a previously highlighted block
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.
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.
Cmd + Shift + 7 will comment the selected lines.
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.
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
Add the below applescript in textarea
awk 'BEGIN{print "/*"}{print $0}END{print "*/"}'
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.