Keyboard shortcut to comment lines in Sublime Text 2

Sublimetext2

Sublimetext2 Problem Overview


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

Sublimetext2 Solutions


Solution 1 - Sublimetext2

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 } },

Solution 2 - Sublimetext2

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 !

Solution 3 - Sublimetext2

I'd like to add, that on my mac by default block comment toggle shortcut is cmd+alt+/

Solution 4 - Sublimetext2

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.

Solution 5 - Sublimetext2

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.

Solution 6 - Sublimetext2

you need to replace "/" with "7", it works on non english keyboard layout.

Solution 7 - Sublimetext2

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 } }
]

Solution 8 - Sublimetext2

In my keyboard (Swedish) it´s the key to the right of "ä": "*".

ctrl+*

Solution 9 - Sublimetext2

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

Solution 10 - Sublimetext2

On a Mac with a US keyboard, you want cmd+/.

Solution 11 - Sublimetext2

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 ~.

Solution 12 - Sublimetext2

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.

Solution 13 - Sublimetext2

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 } },

]

Solution 14 - Sublimetext2

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.

Solution 15 - Sublimetext2

On my laptop with spanish keyboard, the problem seems to be the "/" on the key binding, I changed it to ctrl+shift+c and now it works.

{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": true } },

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1419762View Question on Stackoverflow
Solution 1 - Sublimetext2Andrew BarrettView Answer on Stackoverflow
Solution 2 - Sublimetext2EvrenView Answer on Stackoverflow
Solution 3 - Sublimetext2VadimRostokView Answer on Stackoverflow
Solution 4 - Sublimetext2happymoepView Answer on Stackoverflow
Solution 5 - Sublimetext2marcelo.guedesView Answer on Stackoverflow
Solution 6 - Sublimetext2ganchanView Answer on Stackoverflow
Solution 7 - Sublimetext2Gísli Freyr SvavarssonView Answer on Stackoverflow
Solution 8 - Sublimetext2daniel_arenView Answer on Stackoverflow
Solution 9 - Sublimetext2BrennQuinView Answer on Stackoverflow
Solution 10 - Sublimetext2ArtOfWarfareView Answer on Stackoverflow
Solution 11 - Sublimetext2Flávio PereiraView Answer on Stackoverflow
Solution 12 - Sublimetext288JeffreyHallView Answer on Stackoverflow
Solution 13 - Sublimetext2ShahnawazView Answer on Stackoverflow
Solution 14 - Sublimetext2Er CEO Vora MayurView Answer on Stackoverflow
Solution 15 - Sublimetext2diego a.View Answer on Stackoverflow