Multi-line comments in Xcode
XcodeXcode Problem Overview
Is there a way to comment various lines at the same time in Xcode IDE? Selecting which lines to comment, then clicking somewhere et voilá.. the /* ... */ characters wrapping the code.
Thank you.
Xcode Solutions
Solution 1 - Xcode
Command + Shift + 7
or
Command + /
This inserts //
in front of every selected line.
Solution 2 - Xcode
Xcode Version 6.1
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Also see taskbar Editor>Structure "(un)Comment Selection" as user 2137640 pointed out.
Solution 3 - Xcode
The answer is actually very simple if you want to comment a continuous sequence of lines. Select the consecutive lines, then simply press ⌘ /.
I have no idea how to comment multiple non-consecutive lines. Maybe somebody else can help with this, if it is even possible (I doubt it.)
Solution 4 - Xcode
There is such a function in the menu. Try: Edit->Insert Text Macro->C->Comment Section. It will create a (multi-line) comment around the currently selected text.
However, using the menu is probably often slower than manually inserting the comments. But, you can also bind a key to the menu item via the preferences key binding settings.
Solution 5 - Xcode
For single line Comment use ⌘+/
For multiline Comment you need to install CComent plugin
to install plugin manager use alcatraz
Solution 6 - Xcode
I've been using the Command + Shift + 7 for years, but now in Xcode 13.1
it just started to open the help menu instead of commenting the selected block.
Apparently the new command for commenting a selection of code is:
Command + Shift + ?
Solution 7 - Xcode
in Xcode 7.x
Shortcuts:
To Comment: Select the code to be comment, ⌘ + /
To uncomment: Select the code an press ⌘ + /
Solution 8 - Xcode
Got it! You have to un-indent the lines so the comments are the first character on the line, not a tab or whitespace - then pressing CMD+/ works. Just tried it in XCode 5.1.1, works like a charm.
Solution 9 - Xcode
This worked !
Higlight the desired lines then press Command + /
The same rule goes for uncommenting.
Solution 10 - Xcode
For xcode 8 ->
sudo /usr/libexec/xpccachectl
restart your computer