Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut to comment out a block of code with sublime text

I want to comment out a block of code in sublime text.

I see it in RailsCasts, but don't think he uses sublime text ... to do the following ...

if (uncommented)   some uncommented example   # if (commented)    #   some commented example code   # end end 

Is there a shortcut in sublime text that I can use to insert the block of #'s?

like image 965
user749798 Avatar asked Jul 12 '12 01:07

user749798


People also ask

How do you comment out a block of code in Sublime Text?

The shortcut to comment out or uncomment the selected text or current line: Windows: Ctrl + / Mac: Command ⌘ + / Linux: Ctrl + Shift + /

How do you comment a block of code shortcut?

In the C/C++ editor, select multiple line(s) of code to comment out. To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ )

How do I comment in Sublime Text HTML?

Ctrl + Shift + / (or Cmd + Shift + / if you're on a Mac). Right click in the current buffer and select HTML Nest Comments -> Comment/Uncomment Selection . Open an HTML file, pop out the console in Sublime Text from View -> Show Console, and type view.

How do you comment out the whole block or code?

Fortunately, if you use Visual Studio Code, commenting out a block of code is really quick and easy. All you need to do is select that code block with your mouse, then press the following key combination: Ctrl + K then press Ctrl + C if you're using Windows. Command + K then press Command + C if you're on a Mac.


2 Answers

The shortcut to comment out or uncomment the selected text or current line:

  • Windows: Ctrl+/
  • Mac: Command ⌘+/
  • Linux: Ctrl+Shift+/

Alternatively, use the menu: Edit > Comment

For the block comment you may want to use:

  • Windows: Ctrl+Shift+/
  • Mac: Command ⌘+Option/Alt+/
like image 140
Randall Ma Avatar answered Oct 12 '22 08:10

Randall Ma


You're looking for the toggle_comment command. (Edit > Comment > Toggle Comment)

By default, this command is mapped to:

  • Ctrl+/ (On Windows and Linux)
  • Command ⌘+/ (On Mac)

This command also takes a block argument, which allows you to use block comments instead of single lines (e.g. /* ... */ as opposed to // ... in JavaScript). By default, the following key combinations are mapped to toggle block comments:

  • Ctrl+Shift+/ (On Windows and Linux)
  • Command ⌘+Alt+/ (On Mac)
like image 37
Ajedi32 Avatar answered Oct 12 '22 08:10

Ajedi32