Sublime Text Keyboard Shortcut to Comment Out Lines

It is possible to quickly comment-out large blocks of code in Sublime Text using keyboard shortcuts, which we will learn to use in this article.

 

Single-Line Comments Shortcut

To add single-line comments, put the text cursor on the line to comment-out or highlight multiple lines and type CMD + / on Mac, for Linux and Windows use CTRL + /.

 

Single line comment highlight

 

The above command will output single-line comments like this in JavaScript:

 

// $('#foo').click(function() {
// 	$(this).toggleClass('bar');
// });

 

Block Comment Shortcut

Highlight the block of code to comment out and press CMD + OPT + /  on Mac, for Linux and Windows use CTRL + SHIFT + / to wrap it in a block comment.

 

Block comment highlight

 

The above command will output block comments like this in JavaScript:

 

/*$('#foo').click(function() {
	$(this).toggleClass('bar');
});*/

 

Conclusion

If the language you are using does not support single-line comments, Sublime Text will automatically use block commenting.

sublime