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
You can assign this yourself very easily, here goes a step by step explaination.
1.) In you xCode .m file type the following, it does not matter where you type as long as it's an empty area.
/*
*/
2.)Highlight that two lines of code then drag and drop onto 'code snippet library panel' area (it's at the bottom part of Utilities panel). A light blue plus sign will show up if you do it right.
3.) After you let go of your mouse button, a new window will pop up and will ask you to add name, short cut etc; as shown. As you can see I added my shortcut to //. So every time I want a block comment I will type //. Hope this helps
If you're looking a way to convert autogenerated comment from Add Documentation
action (available under cmd-shift-/) you might find it useful too:
function run(input, parameters) {
var lines = input[0].split('\n');
var line1 = lines[0];
var prefixRe = /^( *)\/\/\/?(.*)/gm;
var prefix = prefixRe.test(line1) ? line1.replace(prefixRe, "$1") : ""
var result = prefix + "/*\n";
lines.forEach(function(line) {
result += prefix + line.replace(prefixRe, "$2") + '\n';
});
result += '\n' + prefix + ' */';
return result;
}
Rest the same as in @Charles Robertson answer:
In xcode 11.1 swift 5.0
select the code you would like to add block comment then press ⌥ + ⌘ + /
There is a symbol before help menu on xcode which has Edit user script. On Un/Comment Selection under comments section change my $cCmt = "//"; to my $cCmt = "#"; or whatever your IDE works with. Then by selecting lines and command + / (It's my xcode default) you can comment and uncomment the selected lines.
@Nikola Milicevic
Here is the screenshot of the indentation issue. This is very minor, but it is strange that it seems to work so well, in your example visual.
I am also adding a screenshot of my Automator set-up...
Thanks
Update:
If I change the script slightly to:
And then select full lines in XCode, I get the desired outcome:
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:
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.