Skip to content

How to Get Rid of Empty Lines of Code in Any Text Editor

Sometimes, you’ll look at a CSS, PHP, JavaScript, or other code or markup file, and see one or more empty lines between every line of actual content.

It might look something like this (pay attention to the lines, not the code itself):

class EM_DEBUG {

	public function __call( $name, $arguments ){

		global $dbem_debug_options;

		return $dbem_debug_options[$name];



WordPress files sometimes develop this problem, especially if you use its built-in “Theme Editor” and “Plugin Editor” features. More generally, empty lines of code can crop up when different pieces of software interpret line breaks differently.

Regardless of how you’re getting empty lines in your code, this article gives a quick walkthrough on how to delete them, all at once—without having to scroll through and hit “delete” hundreds of times. This method will work equally for removing blank lines no matter the programming language—it’ll work for PHP, JavaScript, Java, C#, or whatever else you happen to be into.

Why Empty Lines of Code are a Problem

The short answer is, “They’re more an annoyance than a problem.” They won’t actually break anything—which is why your code continues to run—but they make it awkward to read and change your code, especially if you’re dealing with multiple line breaks per line of real code. They also add just a tiny bit of size to your files, which is nice to reduce.

How to Bulk-Delete Empty Lines of Code

Here’s a very easy text editor trick to fix that problem when it arises. The video below covers deleting empty lines of code in Sublime Text, but any text editor will have a very similar process for doing the same trick. The demo itself starts at 1:50 in the video.

And here’s a text guide to the same process:

Step-by-Step: How to Remove Blank Lines of Code Using a Text Editor

  1. In the file you want to clean up, select two adjacent lines that have nothing in them. (To do this, you can hold down shift and tap the “right” arrow twice.)
  2. Copy your selection with Ctrl+C (PC) or Cmd+C (Mac).
  3. Open up your text editor’s find-replace tool. This will usually be with Ctrl+H (PC) or Cmd+H (Mac).
  4. In the “Find…” field, paste in your selection. It should look like two empty lines.
  5. In the “Replace…” field, paste in your selection again, and then hit delete once. It should look like one empty line.
  6. Run “Replace All.” This step will replace all “double newlines” with “single newlines”—with the effect that empty lines are removed while your code itself stays in place.

And that’s it! As a note, this method even works to quickly shrink down files with multiple useless blank lines per line of real code, like this:

function ask_why() {

	echo 'Seriously, ';

	echo 'why?';


However, you may have to hit “Replace All” a few times rather than just once.

Learning to Code?

If you’re looking for more guidance on the wide world of web development, check out our free courses, especially our in-depth guide to PHP for WordPress development:

PHP for WordPress Development: The Free Course

We’re also always happy to say hi and field your questions in our Facebook group. Thanks for reading!

Yay! 🎉 You made it to the end of the article!
Fred Meyer

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Andrea Bizioli
May 12, 2020 11:30 am

I use PSPad editor for this task, it has an integrated “Delete empty lines” function that works flawlessly

May 2, 2020 4:03 am

For CSS I use notepad++. In search and replace search for ^\r and replace with \n
Make sure regular expression is selected. This replaces all blank lines and makes editing easy. Not sure why you would need any blank lines at all. I would be interested to know.

March 30, 2019 11:09 am

You are a lifesaver lol!! Funny how such a simple thing could be so frustrating and so easily fixed. And I’m not sure of WHY it happens, but I have noticed it happens with my FTP files in FileZilla, so Mark may be on to something.

October 18, 2017 7:27 am

Multiple line spacing often happens because FileZilla is not using binary transfer mode. It usually occurs when the data is transferred over FTP, in ASCII mode. In FileZilla the setting is in Edit > Settings > Transfers > File Types > Default transfer type > Binary.

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...