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
- Open your document in Notepad++.
- Move the caret (text cursor) to the beginning of the file (Ctrl+Home).
- Press Ctrl+H to open the Replace dialog.
- In the "Find what" field, enter:
^\s*$\r?\n
- Leave the "Replace with" field empty.
- Check the box next to "Regular expression" in the Search Mode section.
- 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:
^
: Start of line\s*
: Any number of whitespace characters (including none)$
: End of line\r?\n
: Line break (works for both Windows and Unix-style line endings)
Method 2: Using Built-in Line Operations
Notepad++ provides built-in options for removing empty lines:
- To remove lines that are completely empty:
Edit → Line Operations → Remove Empty Lines - 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:
- Open your document in Notepad++.
- Move the caret (text cursor) to the beginning of the file (Ctrl+Home).
- Press Ctrl+H to open the Replace dialog.
- In the "Find what" field, enter:
^\s*$\r?\n
- Leave the "Replace with" field empty.
- 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":
- Open your document in Notepad++.
- Press Ctrl+Shift+F to open the "Find in Files" dialog.
- In the "Find what" field, enter:
^\s*$\r?\n
- Leave the "Replace with" field empty.
- In Directory, browse to the directory containing the files where empty lines will be removed.
- Check the box next to "Regular expression" in the Search Mode section.
- Click "Replace in Files"