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
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.
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:
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.
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:
I use this sequence (not a 'linear' shortcut but useful anyway):
(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:
This way you can be sure that those keys are not mapped (except if you assigned them before to another function)
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:
Comments using // notation
Comments using /* */ notation
In Android studio CTRL + SHIFT + / for windows.
Source: Stackoverflow.com