Keyboard shortcut to comment lines in Sublime Text 3
Solution 1
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)
Solution 2
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".
Solution 3
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.
Solution 4
U can fix this bug by:
[
{ "keys": ["ctrl+keypad_divide"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+keypad_divide"], "command": "toggle_comment", "args": { "block": true } },
]
it allow to comment with CTRL+/ and CTRL+SHIFT+/ and u can use / on keypad =)
Solution 5
This worked for me.
cmd + /
I'm on Mac OS X El Capitan. Sublime Text 3 (stable build 3114).
Related videos on Youtube
![0x4a6f4672](https://i.stack.imgur.com/swQMb.jpg?s=256&g=1)
Comments
-
0x4a6f4672 over 4 years
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?-
dusan almost 11 yearsOpen the console (View->Show Console) and write this in it:
sublime.log_commands(True)
and pressCtrl+/
andCtrl+Shift+/
. What do you get in the console output? -
MattDMo almost 11 yearsBuild 3049 has just been released on the dev channel. Try installing that and seeing if the issue has been fixed. And, BTW, on OSX it's
Cmd-/
, notCtrl-/
. -
0x4a6f4672 almost 11 years@dusan the console says
command: move_to_group {"group": 6}
for Ctrl+Shift+/ andcommand: focus_group {"group": 6}
for Ctrl+/ -
user137717 over 9 yearsI think this has been fixed in newer builds. Just dl'ed sublime 3 for Ubuntu 13.10 32 bit and control + / is still working the hot key for comments.
-
-
0x4a6f4672 almost 11 yearsYes, it seems to be a bug, but the workaround does not work satisfactory, at least for Linux (Ubuntu).
-
dusan almost 11 yearsIf you do
sublime.log_commands(True)
again and pressCtrl+/
andCtrl+Shift+/
, do you still get themove_to_group
andfocus_group
commands? -
0x4a6f4672 almost 11 yearsYou are right, you get
toggle_comment {"block": false}
andtoggle_comment {"block": true}
. Somehow theblock:true
command irritated me, it does not seem to work well. Theblock:false
command works as expected. -
Sos over 10 yearsI would like to note that this also worked on Sublime 3 on Win8 ;) thanks!
-
atilkan about 10 yearstoggle have some problems according to css,html,js
-
mathiasfk almost 10 yearsSeems like the keyboard is not properly reconized. Strange that the "/"-key works normally when writing but not for the shortcut.
-
Abram over 9 yearsWorking now in Linux version
-
Oliver Schafeld over 9 yearsI successfully used this workaround in an Ubuntu VM under Windows, too. [On a German keyboard the forward slash is Shift-7 so Shift-/ is a bit tricky to type anyway. (It is available on the numeric keypad.)]
-
Alok Agarwal about 9 yearsThanks This really helped
-
Tobias Hochgürtel about 9 yearsThanks - helped me to understand it complete!
-
Skatox over 7 yearsThis fix the problem for international keyboards on OSX
-
arod over 6 yearsI wonder how did you came up with the alternate
control
andkeypad_divide
? -
f1lt3r over 6 yearsThis seems to work for me on macOS Sierra, however, it does not appear to work with HTML files.
-
dotnetCarpenter almost 6 yearsWorks great on a danish keyboard on Linux - I guess the OS is not important here only the keyboard. Using Sublime 3.1.1 Build 3176
-
Asta86 over 5 yearsWorked on Fedora 29, while ctrl and 7 did not.
-
sebastian romero over 5 yearsThis should be the accepted answer as it is not workaround
-
Awakened almost 4 yearswhat does
"args": { "block": false }
mean ?