banner



How To Comment Multiple Lines Of Code In Visual Studio

Block Comment VSCode

I don't know of a programming linguistic communication that does not support comments.

Lawmaking-comments are incredibly useful. When building out complex functionality, sometimes I'll even write out the whole function in pseudo-code comments before writing whatsoever code.

Comments make code more readable and understandable. This is peculiarly useful if you work on a big squad with lots of people. Every comment you lot write could salvage you and your colleagues some back and forth on slack.

The other great use-instance of comments is rapidly disabling one or multiple lines of code. This comes in handy when debugging your program.

Comments serve two main use-cases:

  • Add data that gives context to your code
  • Quickly disable code while debugging

Here's how to do both in VS Code:

You'll employ this mainly to add data to the menstruum of your programme that will assist your future-self and your colleagues understand what's going on.

Starting time, identify your cursor where you lot'd similar to add the comment. Then, use the VS Code comment shortcut that corresponds to your platform below.

  • On Windows, the shortcut is: CTRL + /
  • On Mac, the shortcut is: Command + /

The VSCode annotate shortcut Mac is very similar to the Windows version.

This is the other main usage of comments. Commenting-out code while debugging. This is probably the most useful shortcut in here. Here'due south how to practice it:

  1. Select the text or code that y'all want to comment out

Select Lines VSCode

  1. Execute the shortcut that corresponds to your platform. (editor.activity.commentLine)
  • Windows: Ctrl + /
  • Mac: Control + /

Comment Out VSCode

You can also uncomment using the same command. Select the code that is currently commented-out and execute the shortcut. It should become un-commented over again.

Un-comment VSCode

Magic.

Once you do it a few times information technology will become muscle memory and boost your productivity. I apply this control constantly and can't imagine non having it.

Some programming languages support cake comments. These are comments which span multiple lines of code (a block). If you want to comment out multiple lines of lawmaking inside the same comment, this is what you're looking for.

To toggle a VSCode comment block, yous tin can utilise editor.action.blockComment:

  • Windows: Shift + Alt + A
  • Mac: Shift + Option + A

Block Comment VSCode

Annotate out code (editor.action.addCommentLine):

  • Windows: Ctrl + Thou + C
  • Mac: Command + M + C

Un-annotate lawmaking (editor.action.removeCommentLine):

  • Windows: Ctrl + Yard + U
  • Mac: Command + K + U

The main divergence with these commands is that they each merely take a single purpose. They practise not toggle code like the slash shortcut. Then, if you keep executing (CTRL + 1000 + C), the comments will keep piling upward, as shown in the screenshot beneath.

Many Comments VSCode

The same is true for united nations-commenting.

Like I said, I think these commands are a lot less handy, and I don't retrieve there's always a practiced reason to them over the slash i... unless of grade yous rebound the slash shortcut to practice something else.

If for some reason y'all want to alter the default key binds for commenting and uncommenting in VS Lawmaking, you can follow these steps:

1. Open the command input

  • Windows: Ctrl + Shift + P
  • Mac: Control + Shift + P

two. Blazon in "keyboard" and select "Preferences: Open Keyboard Shortcuts"

Command Palette VSCode

3. Find "Toggle Line Annotate" and click on the pencil icon to edit it.

Toggle Line Comment VSCode

Happy vs-coding.

Source: https://vscode.one/comment-vscode/

0 Response to "How To Comment Multiple Lines Of Code In Visual Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel