In Sublime Text 2 it was possible to comment out a line or a block of lines with Ctrl+/ and Ctrl+Shift+/. According to the menu Edit > Comment
these shortcuts should be valid, but in Sublime Text 3 (build 3047) they no longer seem to work. Does anybody know the right default keyboard shortcuts for Linux and MacOS? Or is it a bug?
26 Answers
It seems a bug: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=11157&start=0
As a workaround, go to Preferences
->Key Bindings - User
and add these keybindings (if you're using Linux):
{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } }
Update: This also works on Windows 8 (see @Sosi's comment)
You can add the following lines to Preferences / Key Bindings - User:
{ "keys": ["control+keypad_divide"],"command": "toggle_comment", "args": {"block": false} },
{ "keys": ["shift+control+keypad_divide"],"command": "toggle_comment", "args": {"block": true}}
This is how I sorted the problem out - replacing "ctrl" with "control" and "/" with "keypad_divide".
This is a keyboard internationalisation issue.
On a standard US QWERTY keyboard, as used in Australia where Sublime Text is made, / is readily available:
This is not the case with many other keyboards. Take for example the German QWERTZ keyboard. One needs to hit SHIFT+7 to get a /. This is why commenting does not work properly on these keyboards.
Changing the user keybindings to those listed below, will work for the German QWERTZ keyboard.
{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } }
If the problems are occurring with still a different keyboard layout, change the keybindings accordingly.
I'm under Linux too. For me, it only works when I press CTRL+SHIFT+/, and it's like a single comment, not a block comment. The reason is to acceed the / character, I have to press SHIFT, if I do not, sublime text detects that I pressed CTRL + :.
Here it is my solution to get back normal preferences. Write in Key Bindings - User
:
{ "keys": ["ctrl+:"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+:"], "command": "toggle_comment", "args": { "block": true } }
I prefer pressing Ctrl + /
to (un)comment the current line. Plus, I want the cursor to move down one line, thus this way I can (un)comment several lines easily. If you install the "Chain of Command" plugin, you can combine these two operations:
[
{
"keys": ["ctrl+keypad_divide"],
"command": "chain",
"args": {
"commands": [
["toggle_comment", { "block": false }],
["move", {"by": "lines", "forward": true}]
]
}
}
]
On my mac the shortcut is ⌘cmd + / which makes multi line comment but as single lines:
// if ($username && $password) {
// echo "You are good to go";
// } else {
// echo "Fields cannot be blank";
// }
OR
⌥ alt + ⌘cmd + / and it's result is overall comment, from beggining of the selection to the end.
/*
if ($username && $password) {
echo "You are good to go";
} else {
echo "Fields cannot be blank";
}
*/
In case anyone has had further issues with Sublime 3 on Windows 7, the above suggestions all did not work for me. However, when I 1 - reran the app as administrator and 2 - highlighted, and chose Edit -> Comment -> toggle comment, afterwards I was able to use a user preferences set keybinding to toggle comments. I don't really have an explanation for why it worked, except that it did.
sublime.log_commands(True)
and pressCtrl+/
andCtrl+Shift+/
. What do you get in the console output? – dusanCmd-/
, notCtrl-/
. – MattDMocommand: move_to_group {"group": 6}
for Ctrl+Shift+/ andcommand: focus_group {"group": 6}
for Ctrl+/ – 0x4a6f4672