Keyboard shortcut to comment lines in Sublime Text 3

289,450

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

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

Share:
289,450

Related videos on Youtube

0x4a6f4672
Author by

0x4a6f4672

You can find me via Twitter @jofr

Updated on February 19, 2020

Comments

  • 0x4a6f4672
    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
      dusan almost 11 years
      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?
    • MattDMo
      MattDMo almost 11 years
      Build 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-/, not Ctrl-/.
    • 0x4a6f4672
      0x4a6f4672 almost 11 years
      @dusan the console says command: move_to_group {"group": 6} for Ctrl+Shift+/ and command: focus_group {"group": 6} for Ctrl+/
    • user137717
      user137717 over 9 years
      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.
  • 0x4a6f4672
    0x4a6f4672 almost 11 years
    Yes, it seems to be a bug, but the workaround does not work satisfactory, at least for Linux (Ubuntu).
  • dusan
    dusan almost 11 years
    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?
  • 0x4a6f4672
    0x4a6f4672 almost 11 years
    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.
  • Sos
    Sos over 10 years
    I would like to note that this also worked on Sublime 3 on Win8 ;) thanks!
  • atilkan
    atilkan about 10 years
    toggle have some problems according to css,html,js
  • mathiasfk
    mathiasfk almost 10 years
    Seems like the keyboard is not properly reconized. Strange that the "/"-key works normally when writing but not for the shortcut.
  • Abram
    Abram over 9 years
    Working now in Linux version
  • Oliver Schafeld
    Oliver Schafeld over 9 years
    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.)]
  • Alok Agarwal
    Alok Agarwal about 9 years
    Thanks This really helped
  • Tobias Hochgürtel
    Tobias Hochgürtel about 9 years
    Thanks - helped me to understand it complete!
  • Skatox
    Skatox over 7 years
    This fix the problem for international keyboards on OSX
  • arod
    arod over 6 years
    I wonder how did you came up with the alternate control and keypad_divide?
  • f1lt3r
    f1lt3r over 6 years
    This seems to work for me on macOS Sierra, however, it does not appear to work with HTML files.
  • dotnetCarpenter
    dotnetCarpenter almost 6 years
    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
  • Asta86
    Asta86 over 5 years
    Worked on Fedora 29, while ctrl and 7 did not.
  • sebastian romero
    sebastian romero over 5 years
    This should be the accepted answer as it is not workaround
  • Awakened
    Awakened almost 4 years
    what does "args": { "block": false } mean ?