Keyboard shortcut to comment lines in Sublime Text 3

Keyboard ShortcutsSublimetext3

Keyboard Shortcuts Problem Overview


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?

Keyboard Shortcuts Solutions


Solution 1 - Keyboard Shortcuts

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 - Keyboard Shortcuts

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 - Keyboard Shortcuts

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 - Keyboard Shortcuts

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 - Keyboard Shortcuts

This worked for me.

cmd + /

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

Solution 6 - Keyboard Shortcuts

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

Solution 7 - Keyboard Shortcuts

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.

Solution 8 - Keyboard Shortcuts

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

Solution 9 - Keyboard Shortcuts

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.

Solution 10 - Keyboard Shortcuts

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

Solution 11 - Keyboard Shortcuts

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

Solution 12 - Keyboard Shortcuts

i am ubuntu 18 with sublime text 3.2

CTR + /

Solution 13 - Keyboard Shortcuts

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

Solution 14 - Keyboard Shortcuts

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

Solution 15 - Keyboard Shortcuts

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)

Solution 16 - Keyboard Shortcuts

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.

Solution 17 - Keyboard Shortcuts

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

Solution 18 - Keyboard Shortcuts

Sublime 3 for Windows:

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

Solution 19 - Keyboard Shortcuts

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

Solution 20 - Keyboard Shortcuts

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";
}
*/

Solution 21 - Keyboard Shortcuts

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.

Solution 22 - Keyboard Shortcuts

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.

Solution 23 - Keyboard Shortcuts

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

Solution 24 - Keyboard Shortcuts

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.

Solution 25 - Keyboard Shortcuts

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)

Solution 26 - Keyboard Shortcuts

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

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
Question0x4a6f4672View Question on Stackoverflow
Solution 1 - Keyboard ShortcutsdusanView Answer on Stackoverflow
Solution 2 - Keyboard ShortcutsAntonio PantanoView Answer on Stackoverflow
Solution 3 - Keyboard ShortcutsSerge StroobandtView Answer on Stackoverflow
Solution 4 - Keyboard Shortcutsuser4089098View Answer on Stackoverflow
Solution 5 - Keyboard ShortcutsMr. BenedictView Answer on Stackoverflow
Solution 6 - Keyboard ShortcutskaalView Answer on Stackoverflow
Solution 7 - Keyboard ShortcutsTimmView Answer on Stackoverflow
Solution 8 - Keyboard ShortcutsEn-waiView Answer on Stackoverflow
Solution 9 - Keyboard ShortcutsHeitor SilvaView Answer on Stackoverflow
Solution 10 - Keyboard ShortcutsBruno BView Answer on Stackoverflow
Solution 11 - Keyboard ShortcutsRam Prakash SinghView Answer on Stackoverflow
Solution 12 - Keyboard ShortcutsMr CoderView Answer on Stackoverflow
Solution 13 - Keyboard ShortcutsMoh AlaraabiView Answer on Stackoverflow
Solution 14 - Keyboard ShortcutsJabbaView Answer on Stackoverflow
Solution 15 - Keyboard ShortcutsezequielbView Answer on Stackoverflow
Solution 16 - Keyboard ShortcutsAdam NelsonView Answer on Stackoverflow
Solution 17 - Keyboard ShortcutsAriane VRView Answer on Stackoverflow
Solution 18 - Keyboard ShortcutsSergioView Answer on Stackoverflow
Solution 19 - Keyboard ShortcutsGiovanni CapeliView Answer on Stackoverflow
Solution 20 - Keyboard ShortcutsAerogirlView Answer on Stackoverflow
Solution 21 - Keyboard ShortcutsRoboBearView Answer on Stackoverflow
Solution 22 - Keyboard ShortcutsShahnawazView Answer on Stackoverflow
Solution 23 - Keyboard ShortcutsDiwakar SinghView Answer on Stackoverflow
Solution 24 - Keyboard ShortcutsZarko TimaracView Answer on Stackoverflow
Solution 25 - Keyboard ShortcutstimbocfView Answer on Stackoverflow
Solution 26 - Keyboard ShortcutsMarouane KView Answer on Stackoverflow