In Sublime Text 2, how do I enclose a selection in a comment?
Is there a keyboard shortcut for this action?

- 1,478
- 3
- 14
- 32

- 3,571
- 5
- 20
- 10
-
8Don't forget to use the `` tag in your answers, guys. It adds the proper emphasis to the keyboard shortcuts you're sharing. See my answer for an example: http://stackoverflow.com/a/19389142/901641 - hit `edit` on my answer to see exactly how I used the tag. – ArtOfWarfare Oct 15 '13 at 19:10
15 Answers
By default on Linux/Windows for an English keyboard the shortcut is Ctrl+Shift+/ to toggle a block comment, and Ctrl+/ to toggle a line comment.
If you go into Preferences->Key Bindings - Default
, you can find all the shortcuts, below are the lines for commenting.
{ "keys": ["ctrl+/"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+/"], "command": "toggle_comment", "args": { "block": true } },

- 19,721
- 4
- 47
- 52
-
8The default doesn't work for me on Windows. I'm using a laptop, that might be why, i dunno. This worked though, thanks. – qwerty Nov 23 '12 at 14:31
-
14As Vadim notes, on Mac the commands are `cmd+option+/` and `cmd+/`, respectively. – dbn Dec 10 '12 at 00:54
-
1So what about super, instead of command? I see the Linux syntax in my default key bindings, and I've successfully used it in my user key bindings. – Ace Feb 15 '13 at 17:33
-
2If you're a mac user with spanish keyboard you would use this in your user custom key bindings: [ { "keys": ["alt+minus"], "command": "toggle_comment", "args": { "block": false } }, { "keys": ["alt+shift+minus"], "command": "toggle_comment", "args": { "block": true } } ] – Pablo Ezequiel Leone Feb 03 '14 at 10:28
-
So what is "Ctrl+Shift+/" supposed to mean? Don't i need "Shift+7" already to achieve "/"? How would "Ctrl+Shift+/" and "Ctrl+/" be any different from each other then? It's things like that, why shortcuts often don't work. For me, on a Windows 7 machine, answers suggesting "Ctrl+7" are correct. – Janos Jul 26 '14 at 10:35
-
1@noshky - yes, my answer seems to be only valid for people using GB or US keyboards, I've updated it to be explicit about that. (The forward slash key "/" is it's own key on a GB/US keyboard) – Andrew Barrett Jul 28 '14 at 07:21
-
@AndrewBarrett That command doesn't seem to work for Cypher (CQL), but it has always worked for my other files. How can I change my settings such that Cypher knows to comment out lines as well with the same command? – NumenorForLife Jun 15 '15 at 17:28
In the "Preferences->Key Bindings - User"
[
{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } }
]
Just paste it, these are will work great !

- 891
- 6
- 4
-
Worked for me on Ubuntu 19.10 with an Spanish (Latin American) keyboard layout – hectorsq Nov 21 '19 at 23:54
I'd like to add, that on my mac by default block comment toggle shortcut is cmd+alt+/

- 20,617
- 19
- 137
- 193

- 201
- 2
- 2
For German keyboards use ctrl+shift+# to toggle a block comment and ctrl+# to toggle a line comment.
The shortcut in Preferences->Key Bindings - Default
is set to Ctrl+Shift+/ and Ctrl+/, but to actually use the functions, press the keys stated above.

- 4,765
- 8
- 40
- 57

- 141
- 1
- 8
-
Don't suppose you could advise me on how to assign to the hash key? I'm trying to make a shortcut for the 'reindent' command but it's having none of it. Trying: `{ "keys": ["ctrl+#"], "command": "reindent" }` Is there an issue using the **#** character in JSON? – Graham R. Armstrong Apr 10 '15 at 15:42
-
1@GrahamR.Armstrong As the shortcut in that file is assigned to `Ctrl+/` and one needs to press `ctrl + #` to use the function, I would suggest you try to use `/` to assign that key. I don't know what that JSON parser does with the # character. – happymoep Apr 26 '15 at 22:09
In a Brazilian Portuguese ABNT2 keyboard I have a similar issue to the one reported by JoshDM. In the file sublime-keymap I have:
{ "keys": ["ctrl+/"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+/"], "command": "toggle_comment", "args": { "block": true } },
But I have to use ctrl+; and ctrl+shift+;. On my keyboard, ; is on the left of /.
It seems like a bug.

- 20,617
- 19
- 137
- 193

- 482
- 5
- 12
This did the trick for me coming from Brackets and being used to ctrl+/ on the numpad.
[
{ "keys": ["ctrl+keypad_divide"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+keypad_divide"], "command": "toggle_comment", "args": { "block": true } }
]

- 54,987
- 21
- 291
- 190

- 2,275
- 2
- 18
- 13
In my keyboard (Swedish) it´s the key to the right of "ä": "*".
ctrl+*

- 20,617
- 19
- 137
- 193

- 1,714
- 3
- 24
- 41
In keyboard (Spanish), SO: Win7.
Go into Preferences->Key Bindings - Default,
replace..."ctrl+/"]...
by "ctrl+7"...
And don't use the numpad, it doesn't work. Just use the numbers above the letters

- 656
- 10
- 19
Seems like some kind of keyboard mapping bug. I'm Portuguese, so I'm using a PT/PT keyboard. Sublime Text 3 apparently is handling / as ~.

- 20,617
- 19
- 137
- 193

- 21
- 2
Max OS: If you want to toggle comment multiple individual lines versus block comment an entire selection, you can do multi line edit, shift+cmd+L, then cmd+/ in that sequence.
Ctrl+d and Ctrl+Shift+d....
[
{ "keys": ["ctrl+d"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+d"], "command": "toggle_comment", "args": { "block": true } },
]

- 54,987
- 21
- 291
- 190

- 105
- 1
- 12
First Open The Sublime Text 2.
And top menu bar on select the Preferences
.
And than select the Key Bindings -User
.
And than put this code,
[
{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": true } }
]
I use Ctrl+Shift+C, You also different short cut key use.

- 922
- 2
- 14
- 25