How to quickly create a comment block in VSCode

Do you want to know how to quickly create a comment block in VSCode?

Visual Studio Code - the free code editor made by Microsoft has grown from a little project into a household name in just a few short years.

In terms of functionality, Visual Studio Code provides an extensive set of features to help you in the coding process, such as support for syntax highlighting, snippets, code refactoring, debugging, intelligent code completion (or autocomplete), and Git integration. In addition to that, you also get the ability to collaborate and work remotely with your peers in real-time.

To write long comments in source code, you can select multiple lines and comment them out, or even better, use the comment block which was designed for the purpose (if the programming language supports it).

In this article, we would like to show you how to quickly create a comment block in VSCode.

Convert multiple lines into a comment block in Visual Studio Code

  1. Open a text file with Visual Studio Code.
  2. Select the lines that you want to turn into a comment block.
  3. Press Shift + Alt + A hotkey to convert the selected lines into comment block.

Change Block Comment keyboard shortcut in VSCode

If the default keyboard shortcut to convert lines into comment block doesn't fit your workflow, you can always change it.

Open Visual Studio Code and go to File > Preferences > Keyboard Shortcuts. (Code > Preferences > Keyboard Shortcuts on macOS builds).

This will open a new Keyboard Shortcuts tab which lists all available commands along with their assigned hotkey so you can easily change them.

For our purpose, scroll until you see Toggle Block Comment. You can also enter "toggle block" into the search box to quickly jump to the section you want.

Let's say we want to modify Toggle Block Comment keyboard shortcut from Shift + Alt + A to Shift + L. We have to double click somewhere inside Toggle Block Comment section, then press the new hotkey, followed by the Enter key to commit changes.

image-20210521223259801

Please do note that if we try to set the new hotkey to something already assigned to other actions, there will be a warning before you proceed.

image-20210521155017165

If you like this article, you may also want to check out our posts about other nifty little features such as duplicate line or automatic indent in Visual Studio Code.

Click to rate this post!
[Total: 17 Average: 5]

Leave a Comment