How to Remove Empty Lines in Notepad++

Last update: 08-14-2024

Notepad++ offers multiple ways to remove empty lines from your documents. Here are two effective methods:

Method 1: Using Regular Expressions

  1. Open your document in Notepad++.
  2. Move the caret (text cursor) to the beginning of the file (Ctrl+Home).
  3. Press Ctrl+H to open the Replace dialog.
  4. In the "Find what" field, enter: ^\s*$\r?\n
  5. Leave the "Replace with" field empty.
  6. Check the box next to "Regular expression" in the Search Mode section.
  7. Click "Replace All".

Note: Starting at the beginning of the file is crucial, as this method only removes empty lines from the current caret position onwards.

Explanation of the regex:

Method 2: Using Built-in Line Operations

Notepad++ provides built-in options for removing empty lines:

  1. To remove lines that are completely empty:
    Edit → Line Operations → Remove Empty Lines
  2. To remove lines that may contain spaces or tabs but no visible characters:
    Edit → Line Operations → Remove Empty Lines (Containing Blank Characters)

These built-in options are quicker and don't require regex knowledge, making them ideal for most users.

Choose the method that best suits your needs. The regex approach offers more flexibility, while the built-in options provide a simpler, one-click solution.

How to remove blank lines from multiple files in Notepad++

One advantage of the regular expression method we mentioned above, is that it can be applied to multiple files to remove empty lines from all of them at once.

You start the same way:

  1. Open your document in Notepad++.
  2. Move the caret (text cursor) to the beginning of the file (Ctrl+Home).
  3. Press Ctrl+H to open the Replace dialog.
  4. In the "Find what" field, enter: ^\s*$\r?\n
  5. Leave the "Replace with" field empty.
  6. Check the box next to "Regular expression" in the Search Mode section.

But now, instead of "Replace all", click on "Replace All in All Opened Documents".

How to remove blank lines from all files in a folder in Notepad++

Alternatively, you can remove empty lines from all files in a specific folder. The steps are similar, but this time we use "Find in Files":

  1. Open your document in Notepad++.
  2. Press Ctrl+Shift+F to open the "Find in Files" dialog.
  3. In the "Find what" field, enter: ^\s*$\r?\n
  4. Leave the "Replace with" field empty.
  5. In Directory, browse to the directory containing the files where empty lines will be removed.
  6. Check the box next to "Regular expression" in the Search Mode section.
  7. Click "Replace in Files"

0 Comments

Add a new comment: