Search code examples
visual-studio-code

Visual Studio Code - Remove blank lines from code


I use Visual Studio Code as my preferred text editor and I have ran into a problem with regards to the formatting. I have copied code from one file and pasted into another, however when I have pasted the code VSC has placed a blank line between every line with code.

It is quite a big file so I am hoping there is a way to identify all the blank lines at once and remove them?

This is how I want the code to look:

<div>
  <h1></h1>
  <p></p>
</div>

however, on paste it now looks like this:

<div>

  <h1></h1>

  <p></p>

</div>

I have looked online but have been unable to find any direct answer to this :(


Solution

  • Follow the steps

    1. In windows, Press Ctrl+H (quick replace).
    2. Click "Use Regular Expressions".
    3. In Find specify ^$\n.
    4. leave Replace as blank
    5. Click "Replace All" All Blank lines will be deleted.

    enter image description here

    NB: leave the replace box as blank