3

Whenever I use the Xcode keyboard shortcut Command + / for commenting line(s) of code in a Swift/Objective-C source file, the // characters are always placed in the first column. I would much prefer it be at the current indentation.

I guess this is a personal preference, but does anyone know if there's config for it:

For e.g., If I have this code snippet:

    ...
    print("something")
    ...

and I invoke the keyboard shortcut Command + / with the caret positioned on the line containing print statement, I get:

    ...
//      print("something")
    ...

I'd prefer the following behavior instead:

    ...
    print("something")
    ...

I invoke the keyboard shortcut Command + / with the caret positioned on the line containing print statement, I should get:

    ...
    // print("something")
    ...

I guess this is a personal preference, but does anyone know if there's configuration for it?

1

Using the mentioned keyboard shortcut, the comment character // always appear in the first column irrespective of the indentation level. There is no built-in mechanism to configure this behaviour.

  • 1
    I want to accept this answer, after all you say it with such an authoritative air, but how do we know you're correct? I guess this is sort of a null-hypothesis issue. How can you link me to docs that prove you're right? The docs just won't say how to do it if it's not possible... – Michael Apr 3 '18 at 19:44
  • 1
    I have had the exact same query for a long time. From the official documents, I couldn't find anything other than the shortcut. What I learnt is that the indentation behaviour doesn't work this way with comments. Also, tempering with the comment line indentation leads to other undesired effects. Have a look at this and this. – Nimesh Neema Apr 3 '18 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .