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

Android Studio

Android Studio Problem Overview


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 correct sequence, but that's not working.

Android Studio Solutions


Solution 1 - Android Studio

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

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

Solution 2 - Android Studio

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 + -

Solution 3 - Android Studio

From menu, Code -> Comment with Line Commment. So simple. enter image description here

Or, alternatively, add a shortcut as the following: enter image description here

enter image description here

Solution 4 - Android Studio

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 [![First step, find the IDE shortcuts : cmd + shift + A enter shortcuts] 2]2

Second step : Find Comments Shortcut with the finder enter image description here

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

Now enjoy, it works on a macBook without NumPad

edit : cmd + shift + : has conflicts

Edit : this both works without conflicts enter image description hereIssue on MacBook

Solution 5 - Android Studio

At least in Android Studio 2.2.3 with default key mapping, to comment or uncomment a select text, same hotkeys are used as Toggle. Using the hotkeys changes the state from comment to uncomment, and next time Uncomment to comment on next and vice versa.

1. Comment / uncomment a block of code

Comment sample: /* --- Code block ---- */

Hotkey: Ctrl + Shift + "/"

Using the same key combinations again will "toggle" commenting or uncommenting the selection.

2. Comment / uncomment a line of code

Comment sample: // -- Code ---

Hotkey: Ctrl + "/"

Using the same key combinations again will "toggle" commenting or uncommenting the selection.

Note: Key mapping can be changed to different schemes like eclipse, visual studio... or to the custom hotkeys in File -> Settings -> Keymap

Solution 6 - Android Studio

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

Solution 7 - Android Studio

if you are findind keyboard shortcuts for Fix doc comment like this:

/**
 * ...
 */

you can do it by useing Live Template(setting - editor - Live Templates - add)

/**
 * $comment$
 */

Solution 8 - Android Studio

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).

Solution 9 - Android Studio

Windows 10 and Android Studio: Ctrl + / (on small num pad), don't use Ctrl + Shift-7!

Solution 10 - Android Studio

Default shortcuts is under Preferences -> Keymap -> Main Menu -> Code menu

  • Add a shortcut for a single line comment (e.g. Ctrl+ ...)
  • Add a shortcut for a block comment (e.g. Ctrl+...)

You can use default one or customize it by right click

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
QuestionMarcus NoonView Question on Stackoverflow
Solution 1 - Android StudioMarcus NoonView Answer on Stackoverflow
Solution 2 - Android Studiocreep3007View Answer on Stackoverflow
Solution 3 - Android StudiooiyioView Answer on Stackoverflow
Solution 4 - Android StudioNicoolasensView Answer on Stackoverflow
Solution 5 - Android StudioSimmamView Answer on Stackoverflow
Solution 6 - Android StudioiajnrView Answer on Stackoverflow
Solution 7 - Android StudioangrydView Answer on Stackoverflow
Solution 8 - Android StudioCoolMindView Answer on Stackoverflow
Solution 9 - Android StudioTimo Petri Sakari KinnunenView Answer on Stackoverflow
Solution 10 - Android Studioburak isikView Answer on Stackoverflow