[android-studio] Comment shortcut Android Studio

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

This question is related to android-studio keyboard-shortcuts

The answer is


Mac:

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

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


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


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


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.


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.

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)


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.


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

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

line comment: cmd +.

block comment: cmd+alt +.


for German Layout (Deutsches Layout) the default is:

for line Comment: strg + Numpad(/)

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


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


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


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


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.


For Line Comment: Ctrl + /

For Block Comment: Ctrl + Shift + /


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


In the Icelandic MAC keyboard: CMD + -


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


For Line Comment hold both:

Ctrl + /

For Block Comment hold all three:

Ctrl + Shift + /

Same way to remove the comment block.


In LINUX

1.Single line commenting. Ctrl + /

2.For block comment Ctrl + Shift + /


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

cmd + alt(option) + /


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

  • Cmd + /

Comments using // notation

  • Cmd + Opt + /

Comments using /* */ notation


In Android studio CTRL + SHIFT + / for windows.