Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete /* and */ quickly in XCode

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?

like image 858
node ninja Avatar asked Sep 17 '10 03:09

node ninja


People also ask

How do I comment and uncomment in Xcode?

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.

How do I delete a line in Xcode?

Double click into the Key field, then press your preferred key combo. I use ⌘ + D (for Delete Line).


2 Answers

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+/

like image 99
Brock Woolf Avatar answered Oct 11 '22 14:10

Brock Woolf


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.

like image 21
Rob Napier Avatar answered Oct 11 '22 13:10

Rob Napier