In XCode there are some useful functions commented out with /* and a corresponding */. Is there a shortcut that will quickly remove these? Can a shortcut be made using AppleScript, or is there a better way?
By selecting a few lines of code (pressing ⇧+↑ or ⇧+↓), you can comment a bunch of lines in a single shot with the ⌘ + / shortcut. If the lines are already comments, the same shortcut will uncomment them.
Double click into the Key field, then press your preferred key combo. I use ⌘ + D (for Delete Line).
You can comment/uncomment any selected code block with Command + /.
Press key combo again to toggle remove the comments from an already commented code block
In Xcode 4.2 I have to press Command + Shift+/
There's a better way to comment and uncomment code: Cmd + /. It puts //
in front of every line, or removes //
if it's at the front of the line. This has many advantages. It's easier to do in Xcode. It nests correctly. It makes it very clear where commented out code is, even when read outside of an IDE (such as in diffs and code-review tools). It makes it much more obvious in diffs when a huge amount of code has just been committed (removing two lines makes it look like a little change, but you may have just injected hundreds of lines of untested-in-the-current-codebase code).
If you're in a situation where you're hunting for a shortcut, then switching to leading //
is almost certainly a better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With