markmcdermott.io (js, ruby, ...etc) by mark mcdermott

Deleting Blank Lines (VSCode)

A quick regex

10/03/2025

read time: 1 min

I had a textfile today in VSCode where every other line was a blank line and I needed to delete all the blank lines. Turns out there’s a quick regex you can use for this in VSCode search and replace:

^\s*\n

I believe for Windows it would be:

^\s*\r\n

So if you want to cover Unix/Windows, you could do:

^\s*\r?\n

The Windows \r\n was new to me and I had to look it up. I had seen LF and CRLF, but never knew what they meant. Turns out it’s:

So now you know. And knowing is half the battle.