user1419762
user1419762

Reputation: 3571

Keyboard shortcut to comment lines in Sublime Text 2

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

Upvotes: 159

Views: 255401

Answers (15)

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

Upvotes: 8

diego a.
diego a.

Reputation: 1

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

Upvotes: 0

Shahnawaz
Shahnawaz

Reputation: 105

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

]

Upvotes: 0

happymoep
happymoep

Reputation: 141

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.

Upvotes: 14

Mayur Vora
Mayur Vora

Reputation: 962

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.

Upvotes: 0

BrennQuin
BrennQuin

Reputation: 664

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

Upvotes: 5

88JeffreyHall
88JeffreyHall

Reputation: 1

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.

Upvotes: 0

marcelo.guedes
marcelo.guedes

Reputation: 491

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.

Upvotes: 10

VIRUXE
VIRUXE

Reputation: 21

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

Upvotes: 2

VadimRostok
VadimRostok

Reputation: 201

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

Upvotes: 20

daniel_aren
daniel_aren

Reputation: 1924

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

ctrl+*

Upvotes: 6

ArtOfWarfare
ArtOfWarfare

Reputation: 21476

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

Upvotes: 2

Andrew Barrett
Andrew Barrett

Reputation: 19911

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

Upvotes: 288

Evren
Evren

Reputation: 891

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 !

Upvotes: 89

ganchan
ganchan

Reputation: 315

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

Upvotes: 9

Related Questions