A keyboard shortcut to comment/uncomment the select text in Android Studio

后端 未结 9 1359
鱼传尺愫
鱼传尺愫 2021-01-31 13:48

How do I comment out several lines of text selected in the IDE with a control key combination?

I thought that Ctrl + Alt + C was the cor

相关标签:
9条回答
  • 2021-01-31 14:10

    MAC QWERTY (US- keyboard layout) without numpad:

    Line comment : + /
    Block comment: + + /


    MAC QWERTZ (e.g. German keyboard layout):

    Android Studio Version ≥ 3.2:
    Line comment : + Numpad /
    Block comment: + + Numpad /

    thx @Manuel


    Android Studio Version ≤ 3.0:
    Line comment : + -
    Block comment: + Shift + -

    0 讨论(0)
  • 2021-01-31 14:11

    You can also use regions. See https://www.myandroidsolutions.com/2014/06/21/android-studio-intellij-idea-code-regions/

    Select a block of code, then press Code > Surround With... (Ctrl + Alt + T) and select "region...endregion Comments" (2).

    0 讨论(0)
  • 2021-01-31 14:13

    To comment/uncomment one line, use: Ctrl + /.

    To comment/uncomment a block, use: Ctrl + Shift + /.

    0 讨论(0)
  • 2021-01-31 14:14

    I had the same problem, usually, you have found the shortcut but it doesn't work because you have not a NumPad. Actually, the only one issue I found is to set my own shortcut with the one I suppose should works.

    First step, find the IDE shortcuts : cmd + shift + A enter shortcuts

    Second step : Find Comments Shortcut with the finder

    Third step : Set your custom shortcut (I suggest cmd + shift + / or cmd + : )

    Now enjoy, it works on a macBook without NumPad

    edit : cmd + shift + : has conflicts

    Edit : this both works without conflicts Issue on MacBook

    0 讨论(0)
  • 2021-01-31 14:16

    On Mac you need cmd + / to comment and uncomment.

    0 讨论(0)
  • 2021-01-31 14:27

    From menu, Code -> Comment with Line Commment. So simple.

    Or, alternatively, add a shortcut as the following:

    0 讨论(0)
提交回复
热议问题