Multi-line comments in Xcode

Xcode

Xcode 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBigJokeView Question on Stackoverflow
Solution 1 - XcodeGeorg SchöllyView Answer on Stackoverflow
Solution 2 - XcodeCarlView Answer on Stackoverflow
Solution 3 - XcodeKZcodingView Answer on Stackoverflow
Solution 4 - XcodedmeisterView Answer on Stackoverflow
Solution 5 - XcoderinkeshView Answer on Stackoverflow
Solution 6 - XcodeJacob AhlbergView Answer on Stackoverflow
Solution 7 - Xcodekvra13View Answer on Stackoverflow
Solution 8 - XcodeguestView Answer on Stackoverflow
Solution 9 - XcodeEdwin O.View Answer on Stackoverflow
Solution 10 - XcodeAdeelView Answer on Stackoverflow