Removing empty lines in Notepad++
How can I replace empty lines in Notepad++? I tried a find and replace with the empty lines in the find, and nothing in the replace, but it did not work; it probably needs regex.
There is now a built-in way to do this as of version 6.5.2
Edit -> Line Operations -> Remove Empty Lines
or Remove Empty Lines (Containing Blank characters)
You need something like a regular expression.
You have to be in Extended
mode
If you want all the lines to end up on a single line use \r\n
. If you want to simply remove empty lines, use \n\r
as @Link originally suggested.
Replace either expression with nothing.
There is a plugin that adds a menu entitled TextFX
. This menu, which houses a dizzying array of quick text editing options, gives a person the ability to make quick coding changes. In this menu, you can find selections such as Drop Quotes, Delete Blank Lines as well as Unwrap and Rewrap Text
Do the following:
TextFX > TextFX Edit > Delete Blank Lines
TextFX > TextFX Edit > Delete Surplus Blank Lines
- notepad++
- Ctrl-H
- Select Regular Expression
- Enter
^[ \t]*$\r?\n
into find what, leave replace empty. This will match all lines starting with white space and ending with carriage return (in this case a windows crlf) - Click the Find Next button to see for yourself how it matches only empty lines.
- Press ctrl + h (Shortcut for replace).
- In the Find what zone, type
^\R
( for exact empty lines) or^\h*\R
( for empty lines with blanks, only). - Leave the Replace with zone empty.
- Check the Wrap around option.
- Select the Regular expression search mode.
- Click on the Replace All button.