How to remove blank lines in VS Code?

Asked

Viewed 5,356 times

4

I recently copied a file that was on a server and it came all like this, with a blank line between each line of code.

I wonder if there’s a shortcut in the Visual Studio Code, or command to remove these empty lines by VS Code, and be practical and not manually removing the empty lines one by one in the hand...

<!-- BANNER -->

<section id="produtos"  class="container-fluid banner d-flex flex-column justify-content-center align-items-center">

  <div class="row w-100">

    <div class="col-12 text-center pt-1 pt-sm-4">

      <h2 class="tit-banner">TINTAS ESPECIAIS PARA</h2>

      <span id="app" class="texto-banner app"></span>

    </div>

  </div>

</section>

<!-- Lista Produtos -->

<section class="container mb-4">

  <div class="row mt-5">

    <div class="col-12 text-center">

      <h4 class="sec-h4 mb-3">nossa linha completa de tintas</h4>

      <h2 class="sec-h2">Temos o produto certo para te atender</h2>

    </div>

  </div>

</section>

  ...etc...

OBS: Originally this file was not like this, it had no blank lines between the lines of code, and looking directly at the source code of the page that is on the server also there are no such empty lines...

  • 3

    that ai is different from operating system, in linux usually the break is CHR(10) "\n" and in Windows CHR(13)+CHR(10) "\r\n" which is understood as two breaks in other Oses. If you have option to "open as" choosing windows line break, it is to solve

1 answer

7


Follow the following steps:

  • Press CTRL+H
  • Select "Use Regular Expression"
  • Search Box: ^(\s)*$\n
  • Replace Box: Leave Blank.
  • Click on Replace All.

Final result:

inserir a descrição da imagem aqui

Visual Studio Code - delete all Blank Lines - regex

Explanation Regex:

  • The regex is very simple, the line should start(^) and finish($) with spaces, that is, should not contain anything in the line!
  • 1

    That’s right, thank you!

  • 1

    @hugocsl for nothing!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.