HTML comment each line separately, not block comments
Asked Answered
U

2

5

Noob question but I want to be able to quickly comment HTML code using keyboard shortcuts in VS Code. The problem is I get this:

<!-- <div class="whatever">
        <h1>Hellow World!</h1>
        <p>this is code I wrote in HTML</p>
      </div> -->

instead of this:

<!-- <div class="whatever"> -->
   <!-- <h1>Hellow World!</h1> -->
   <!-- <p>this is code I wrote in HTML</p> -->
<!-- </div> -->

Anyone know a good extension for this in VS Code? Thanks

Julien

Undergarment answered 2/3, 2018 at 8:3 Comment(2)
If you want to quickly comment out one line at a time, then comment out one line at a time. There's no two ways about this. Code isn't going to be able to assume you want every line commented out individually when you highlight an entire block to comment out.Homicide
@Homicide PhpStorm does it like that, maybe there is some setting to do this in Visual Studio.Bahia
V
6

See this extension written by me, Toggle Line Comments, that will do what you want.

-- or older answer --

  1. Select through your text - i.e., from some part of the first line to some part of the last line you want separately commented. I.e., highlight your block of HTML to comment.

  2. Shift-Alt-I will put a cursor at the end of each line.

  3. Ctrl-/ will comment each line separately.

This only seems necessary for HTML, not JS or SCSS for example.

I suppose if you wanted to reduce keystrokes you could make a macro for steps 2 and 3 combined.

Veilleux answered 2/3, 2018 at 15:38 Comment(0)
T
1

I found really new extension exactly matches your needs.

Enhanced Comments demo.gif

Tail answered 15/10, 2024 at 18:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.