doovers
doovers

Reputation: 8675

Change comment Indentation Xcode

The default behaviour for the Xcode comment keyboard shortcut is to place // at the far left of the selected lines regardless of indentation.

I'd like to change this so that the indentation is taken into account and the // is inserted just before the text to comment.

For example:

class MyClass {
    func myFunc() {
//        cmd-/ does this
        // I want cmd-/ to do this
    }
}

Is this possible?

Upvotes: 10

Views: 521

Answers (1)

Eric Wiener
Eric Wiener

Reputation: 5947

You can use the Comment Here extension. After downloading:

  1. Restart Xcode
  2. Go to Xcode -> preferences -> key bindings
  3. Search for "Comment Selection" and remove the key binding for it
  4. Search for "Comment Here" and add the key binding "command /" for the toggle comments option.
  5. Your comments are now pretty :)

Upvotes: 5

Related Questions