问题
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...
回答1:
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.
回答2:
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:
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
回答4:
On Mac and Turkish Keyboard it is (both for commenting out and uncommenting)
line comment: cmd +.
block comment: cmd+alt +.
回答5:
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:
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:
- Select the resultant line corresponding to the feature for which the keyboard shortcut is to be reviewed/assigned
- Right-click, and select the desired Add or Remove option.
回答6:
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)
回答7:
for German Layout (Deutsches Layout) the default is:
for line Comment: strg + Numpad(/)
for block Comment: strg+shift+Numpad(/)
回答8:
An Example for a Mac OS X 10.5+ with a German layout keyboard without NumPads:
- Open Preferences
- Search for "Keymap"
- Expand "Main menu"
- Expand "Code"
- Delete all shortcuts (just a suggestion)
- Add a shortcut for a single line comment (e.g. Ctrl++)
- Add a shortcut for a block comment (e.g. Ctrl+alt +)
This way you can be sure that those keys are not mapped (except if you assigned them before to another function)
回答9:
On PC it's by default set to Ctrl + /. This will toggle commenting a selection or current line.
回答10:
In Android stdio CTRL + SHIFT + /
回答11:
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.
}
回答12:
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.
回答13:
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+/
回答14:
For Line Comment: Ctrl + /
For Block Comment: Ctrl + Shift + /
回答15:
Ctrl + Shift + / works well for me on Windows.
回答16:
In LINUX
1.Single line commenting. Ctrl + /
2.For block comment Ctrl + Shift + /
回答17:
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.
回答18:
Are you sure you are using / and not \ ? On Mac I have found by default:
- Cmd + /
Comments using // notation
- Cmd + Opt + /
Comments using /* */ notation
回答19:
If you are used with Eclipse, there is something in Settings>Keymap Keymaps: and you can pick Eclipse to keep the same shortcuts.
回答20:
on mac, using uk english keyboard layout to reach quickcomment in android studio the key combination is:
cmd + alt(option) + /
回答21:
For Line Comment hold both:
Ctrl + /
For Block Comment hold all three:
Ctrl + Shift + /
Same way to remove the comment block.
回答22:
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.
回答23:
In the Icelandic MAC keyboard: CMD + -
来源:https://stackoverflow.com/questions/25523490/comment-shortcut-android-studio