191

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?

JJJ
  • 32,902
  • 20
  • 89
  • 102
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
  • 3
    Open the console (View->Show Console) and write this in it: `sublime.log_commands(True)` and press `Ctrl+/` and `Ctrl+Shift+/`. What do you get in the console output? – dusan Jul 19 '13 at 13:16
  • 1
    [Build 3049](http://www.sublimetext.com/3dev) 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-/`, not `Ctrl-/`. – MattDMo Jul 19 '13 at 14:12
  • 6
    @dusan the console says `command: move_to_group {"group": 6}` for Ctrl+Shift+/ and `command: focus_group {"group": 6}` for Ctrl+/ – 0x4a6f4672 Jul 19 '13 at 14:30
  • 1
    I 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. – user137717 Nov 26 '14 at 15:15

27 Answers27

318

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)

dusan
  • 9,104
  • 3
  • 35
  • 55
  • 4
    Yes, it seems to be a bug, but the workaround does not work satisfactory, at least for Linux (Ubuntu). – 0x4a6f4672 Jul 19 '13 at 16:29
  • 1
    If you do `sublime.log_commands(True)` again and press `Ctrl+/` and `Ctrl+Shift+/`, do you still get the `move_to_group` and `focus_group` commands? – dusan Jul 19 '13 at 17:30
  • 1
    You are right, you get `toggle_comment {"block": false}` and `toggle_comment {"block": true}`. Somehow the `block:true` command irritated me, it does not seem to work well. The `block:false` command works as expected. – 0x4a6f4672 Jul 22 '13 at 08:39
  • 1
    I would like to note that this also worked on Sublime 3 on Win8 ;) thanks! – Sos Mar 13 '14 at 11:05
  • 1
    toggle have some problems according to css,html,js – atilkan Jun 15 '14 at 19:34
  • Working now in Linux version – Abram Dec 31 '14 at 00:58
  • I 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.)] – Oliver Schafeld Jan 26 '15 at 08:24
  • This seems to work for me on macOS Sierra, however, it does not appear to work with HTML files. – f1lt3r Feb 06 '18 at 20:10
  • Works 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 – dotnetCarpenter Aug 30 '18 at 00:40
  • what does `"args": { "block": false }` mean ? – Awakened Sep 06 '20 at 17:35
94

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

Alen Siljak
  • 2,482
  • 2
  • 24
  • 29
Antonio Pantano
  • 4,592
  • 2
  • 23
  • 26
46

This is a keyboard internationalisation issue.

On a standard US QWERTY keyboard, as used in Australia where Sublime Text is made, / is readily available: US QWERTY keyboard

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. German QWERTZ keyboard

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.

Community
  • 1
  • 1
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
16

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 =)

Mwiza
  • 7,780
  • 3
  • 46
  • 42
user4089098
  • 161
  • 1
  • 2
13

This worked for me.

cmd + /

I'm on Mac OS X El Capitan. Sublime Text 3 (stable build 3114).

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Mr. Benedict
  • 809
  • 2
  • 10
  • 15
9

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

Frank T
  • 8,268
  • 8
  • 50
  • 67
kaal
  • 335
  • 3
  • 12
8

On OSX Yosemite, I fixed this by going System Preferences, Keyboard, then Shortcuts. Under App Shortcuts, disable Show Help menu which was bound to CMD+SHIFT+7.

keyboard settings

My keyboard layout is Norwegian, with English as the OS language.

Abhishek
  • 6,912
  • 14
  • 59
  • 85
Timm
  • 157
  • 2
  • 8
7

It's simpler than you think press cmd + / in mac.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
En-wai
  • 71
  • 1
  • 1
4

In my notebook keyboard, a ABNT 2, I can use the CTRL+; shortcut as the default comment action for blocks and lines. The same shortcut to uncomment.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
  • Seems like the keyboard is not properly reconized. Strange that the "/"-key works normally when writing but not for the shortcut. – mathiasfk Aug 06 '14 at 13:58
4

For Brazilian ABNT Keyboards you do Ctrl + ; to comment and repeat it to remove the comment.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Bruno B
  • 51
  • 1
3

Use Ctrl + / for single line comment and
Ctrl + Alt + / for block or multiline comments.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
3

i am ubuntu 18 with sublime text 3.2

CTR + /

Mr Coder
  • 507
  • 3
  • 13
2

On MAC instead of shift use ALT like this CMD + ALT + /

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Moh Alaraabi
  • 193
  • 6
2

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}]
            ]
        }
    }
]
Jabba
  • 19,598
  • 6
  • 52
  • 45
1

Had the same issue. Check with sublime.log_input(True) command on the console to see what keys are being detected with the CTRL+/ and SHIFT+CTRL+/ shorcuts. Then replace the shortcuts with those. (Changing / for keypad_divide worked for me)

Mwiza
  • 7,780
  • 3
  • 46
  • 42
ezequielb
  • 463
  • 3
  • 7
1

Make sure the file is a recognized type. I had a yaml file open (without the .yaml file extension) and Sublime Text recognized it as Plain Text. Plain Text has no comment method. Switching the file type to YAML made the comment shortcut work.

Adam Nelson
  • 7,932
  • 11
  • 44
  • 64
1

For me, on Mac OS Sierra :

{ "keys": ["super+forward_slash"], "command": "toggle_comment", "args": { "block": true } }, { "keys": ["super+alt+:"], "command": "toggle_comment", "args": { "block": false } },
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Ariane VR
  • 11
  • 1
1

Sublime 3 for Windows:

Add comment tags -> CTRL + SHIFT + ;
The whole line becomes a comment line -> CTRL + ;

Syscall
  • 19,327
  • 10
  • 37
  • 52
Sergio
  • 11
  • 1
1

If the shortcut ctrl+?, ctrl+shift+? or ctrl+/ is not working, try switching to another, like ctrl+1, ctrl+shift+1, it worked for me.

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

Marian Nasry
  • 821
  • 9
  • 22
1

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";
}
*/
Aerogirl
  • 369
  • 4
  • 17
1

As a workaround, go to Preferences->Key Bindings - User and add these keybindings (if you're using Mac):

{ "keys": ["super+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["super+shift+7"], "command": "toggle_comment", "args": { "block": true } }
0

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.

RoboBear
  • 5,434
  • 2
  • 33
  • 40
0

Open sublime Text 3 and go to Preferences menu and the click on Key Bindings then paste this code to make a comment shortcut with CTRL+D.

[{ "keys": ["ctrl+d"],"command": "toggle_comment", "args": {"block": false}},]

then save it. now you can use shortcut.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Shahnawaz
  • 105
  • 1
  • 12
0

On windows, use Ctrl + Shift + ?. You will be able to comment the HTML.

adiga
  • 34,372
  • 9
  • 61
  • 83
Diwakar Singh
  • 101
  • 1
  • 1
0

This worked just fine for me on Win 10:

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

note that "[ ]" are nesassary and it will give you an error if you miss them.

0

I might be late to the party but as of my build 3176 it appears the bug is fixed. Just used Ctrl+T and it worked for a CSS file (Kubuntu 18.10)

timbocf
  • 25
  • 1
  • 5
-1

In Windows use ctrl + shift + : to comment for Python.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Marouane K
  • 31
  • 2
  • 6