173

I'm searching for useful Android Studio keyboard shortcut for commenting code, as in Sublime Text or Eclipse.

When I press either cmd+/ or cmd+maj+/ nothing happens...

2
  • 3
    Are you using an english keyboard layout? I am using a german layout where there is no / (there it is Shift + 7), so I remapped it to cmd + 7 as well as cmd + numpad / which is working fine for me.
    – Tim
    Aug 27, 2014 at 9:32
  • 4
    cmd + numpad / is doing it. German keyboard. Ubuntu 14.04
    – mcExchange
    Mar 6, 2016 at 16:53

26 Answers 26

307

Mac With Numeric pad

Line Comment hold both: Cmd + /

Block Comment hold all three: Cmd + Alt + /

Mac

Line Comment hold both: Cmd + + =

Block Comment hold all three: Cmd + Alt + + =


Windows/linux :

Line Comment hold both: Ctrl + /

Block Comment hold all three: Ctrl + Shift + /

Same way to remove the comment block.


To Provide Method Documentation comment type /** and press Enter just above the method name (

It will create a block comment with parameter list and return type like this

/**
 * @param userId 
 * @return
 */
public int getSubPlayerCountForUser(String userId){}
5
  • 41
    If you use the "/" from the numeric pad (if you have one), on the right of the keyboard, you don't have to edit the macro. Seems that "/" on the numeric pad, and "/" in the middle of the keyboard are not the "same" key. (PC/French)
    – Dazzibao
    Jan 1, 2015 at 0:30
  • In my experience you should stick to using the line comment instead of the block comment, as removing the block comment modifies the documentation /** */
    – Jacob R
    Nov 26, 2015 at 15:01
  • 1
    @PeterSmith Yes, but it still disrupts it. Try it for yourself; select some block of code with documentation, and press Ctrl + Shift + / twice
    – Jacob R
    Nov 26, 2015 at 16:01
  • 1
    I'm on Mac with Android Studio 4.2.1 with a danish keyboard and no numeric keyboard. When I press the combo cmd + +=, then nothing happens. I have tried the other answers here and also no luck with these.
    – neoneye
    Jun 9, 2021 at 13:30
  • does not work on Windows
    – VanessaF
    Mar 4 at 1:58
54

In spanish keyboard without changing anything I can make a comment with the keys:

cmd + -

OR

cmd + alt + -

This works because in english keyboard / is located at the same place than - on a spanish keyboard

3
  • 2
    For some reason it stopped working for me. Now this combo just folds the block of code. Any clue? Mar 13, 2018 at 22:48
  • Yeah the second one just folds every possible block of code in the file, don't use it
    – Mr. Robot
    Dec 2, 2022 at 15:49
  • Doesn't work; it collapses, it doesn't comment
    – moyo
    Dec 14, 2022 at 10:25
26

Be sure you use the slash (/) on right side of keyboard.

For Line Comment:

Ctrl + /

For Block Comment:

Ctrl + Shift + /

You can see all keymap in Android Studio: Help ➤ Default Keymap Reference

0
22

On Mac and Turkish Keyboard it is (both for commenting out and uncommenting)

line comment: cmd +.

block comment: cmd+alt +.

3
  • 2
    cmd + . shrinks method if you are inside a method otherwise it does not work. cmd + alt + . displays green dialog box that's written "There are no custom foldings in the current file" Doesn't these shortcuts work now in AS 3.1? I'm using MacBook Air 2017.
    – Thracian
    Jun 3, 2018 at 15:22
  • @Thracian doesnt work on 3.1+, also there are some other bugs like you cant type @ in turkish keyboard Jul 3, 2018 at 14:19
  • @EgeKuzubasioglu i assigned my own shortcuts. It was quite annoying to manually comment or block-comment every often. I use AS 31.3, i can type @ with alt+q, what's not working with yours?
    – Thracian
    Jul 3, 2018 at 14:35
22

An Example for a Mac OS X 10.5+ with a German layout keyboard without NumPads:

  1. Open Preferences
  2. Search for "Keymap"
  3. Expand "Main menu"
  4. Expand "Code"
  5. Delete all shortcuts (just a suggestion)
  6. Add a shortcut for a single line comment (e.g. Ctrl++)
  7. Add a shortcut for a block comment (e.g. Ctrl+alt +)
  8. This way you can be sure that those keys are not mapped (except if you assigned them before to another function)

    enter image description here

18

Reviewing and Changing Keyboard Shortcuts in Android Studio

Keyboard shortcuts can be configured (and reviewed) via the Settings dialog, accessible via File -> Settings.

Once this dialog appears, to review (and/or add) a shortcut, do the following:

Modify shortcut dialog

  1. Select Keymap in the list on the left. Note that there is a "Keymaps" option, and depending on the original selection, shortcuts assigned to a given feature differ based on the Keymap.

  2. Type "comment" or text corresponding to the feature for which the keyboard shortcut is to be reviewed/assigned. Each match has a line entry in the list below, and keyboard shortcuts are shown right-justified along with the feature. For example, both CTRL+ALT+SLASH and CTRL+K, CTRL+C are the two assignments for creating a line comment.

To modify a shortcut:

  1. Select the resultant line corresponding to the feature for which the keyboard shortcut is to be reviewed/assigned
  2. Right-click, and select the desired Add or Remove option.
13

Comment method like pro developers:

Windows/linux:

Line Comment : Ctrl + /

Block Comment : Ctrl + Shift

Method Commenting:

Type `/**` and press `Enter Key`

it will add the comment snippet like we see in standard documentation, give it a try this once.

/**
 * 
 * @param addOpacity
 */
public void setOpacityOnUserImage(boolean addOpacity) {
// Your business logic. 
}
2
  • 1
    Please upvote if you enjoyed using method commenting shortcut. Nov 28, 2017 at 5:17
  • Congratulation for 1500 reputation..!
    – Pranav P
    Jan 28, 2020 at 23:51
13

In Android studio CTRL + SHIFT + / for windows.

12

for German Layout (Deutsches Layout) the default is:

for line Comment: strg + Numpad(/)

for block Comment: strg+shift+Numpad(/)

11

I use this sequence (not a 'linear' shortcut but useful anyway):

  • alt+c then alt+b (holding alt) for block comment
  • alt+c then alt+l (holding alt) for line comment

(they use the android studio menu)

0
8

On PC it's by default set to Ctrl + /. This will toggle commenting a selection or current line.

6

I am working with a german keyboard and the slash (/) is on the 7 key, meaning access would be Ctrl + Shift + 7. However, this does not work as this is predefined as something with bookmark 7.

I went to settings (search for keymap) and deleted all existing shortcuts. I than added Ctrl + 7, confirmed deletion of bookmark shortcut and now can work well.

6

For Line Comment: Ctrl + /

For Block Comment: Ctrl + Shift + /

5

For multiline comment in android studio

select the statement that you want to commented then

use ctrl+shift+/

and for removing mutiline comment 

select the statement that you want to uncommented then

use **ctrl+shift+/**

SINGLE LINE COMMENT

For single line comment

use ctrl+/

1
  • 1
    How does this differ from Hugo Gresse's answer?
    – Ken Y-N
    Feb 13, 2018 at 5:47
3

Ctrl + Shift + / works well for me on Windows.

3

In LINUX

1.Single line commenting. Ctrl + /

2.For block comment Ctrl + Shift + /

2
  • This seems like a repeat of many of the existing answers, including this answer.
    – Pang
    Sep 18, 2017 at 10:22
  • I think no one given answer for linux
    – Ramesh
    Sep 18, 2017 at 10:27
2

on mac, using uk english keyboard layout to reach quickcomment in android studio the key combination is:

cmd + alt(option) + /

2

Mac (French-Canadian Keyboard):

Line Comment hold both: Cmd + É

Block Comment hold all three: Cmd + Alt + É

"É" is on the same position as "?/" in english one.

2

Are you sure you are using / and not \ ? On Mac I have found by default:

  • Cmd + /

Comments using // notation

  • Cmd + Opt + /

Comments using /* */ notation

2

If you are used with Eclipse, there is something in Settings>Keymap Keymaps: and you can pick Eclipse to keep the same shortcuts.

1

For Line Comment hold both:

Ctrl + /

For Block Comment hold all three:

Ctrl + Shift + /

Same way to remove the comment block.

1

In android studio you can do single comment with (go to line then Ctrl+/) and block comment with ( select text then Ctrl+Shift+/)

Also if you want to change color of commented text go to File->Settings->IDE settings->Editor->Color & fonts->Java->(Line comment or block comment) and change properties. I prefer it to be green which is used in notepad++ editor.

1

In the Icelandic MAC keyboard: CMD + -

1

You can add three slashes.

/// Add comments

this can clear the "comment out code 2 lines" issues.

0

Mac:

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

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

0

I noticed that command Ctrl + Shift + / works on Windows only in case if there is no indentation on the left. I.e. if you need to comment out an entire function or class, you must additionally press Enter at the top and bottom of the class/function. It helped me.

Not the answer you're looking for? Browse other questions tagged or ask your own question.