Notepad++

How to Remove Empty Lines in Notepad++

How to Remove Empty Lines in Notepad++

Blank lines pile up fast — in log files, CSV exports, code, anywhere text gets copied and reformatted.

Knowing how to remove empty lines in Notepad++ saves real time. The editor handles it through Find and Replace with regex, macros, plugins, and scripts.

This guide covers every method, including the exact regex patterns for empty lines vs. whitespace-only lines, batch cleanup across multiple files, and what to do before you run Replace All on structured data.

By the end, you will know which approach fits your file type and how to avoid the mistakes that delete more than you intended.

How Do You Remove Empty Lines in Notepad++ Using Find and Replace?

maxresdefault How to Remove Empty Lines in Notepad++

The fastest way to remove empty lines in Notepad++ is through the Find and Replace dialog using a regular expression pattern. Open it with Ctrl+H, switch Search Mode to “Regular expression,” enter ^r?n in the Search field, leave Replace empty, and click Replace All.

That single operation removes every line containing zero characters across the entire file, regardless of size.

Notepad++ handles this well even on large files. The editor uses the Boost regex library v1.90 (as of v8.9.1), which processes blank line patterns efficiently without freezing the interface (Notepad++ User Manual, 2024).

The 2024 Stack Overflow Developer Survey, covering 65,437 responses, confirmed that Notepad++ beat out Visual Studio for second place among “Other Coders” — which tells you this tool has a real, active user base that actually relies on features like this.

What Regex Pattern Removes Blank Lines vs. Whitespace-Only Lines

Two patterns, two different problems:

  • ^r?n — targets lines with zero characters (no spaces, no tabs)
  • ^s$r?n or ^(sn)+ — targets lines that look empty but contain spaces or tabs

The s in the second pattern matches any whitespace character before the line ending. If your file came from a copy-paste or a CSV export, whitespace-only lines are actually more common than truly empty ones.

Use View > Show Symbol > Show All Characters to see what’s actually on those lines before choosing a pattern. Invisible dots or arrows mean whitespace is present.

How to Remove Empty Lines Without Affecting Indented Code

Use ^r?n rather than ^s$r?n when working inside code files.

The ^s$ pattern matches lines that contain only spaces or tabs, which includes blank lines between indented blocks. In Python or YAML files, that removes intentional spacing and breaks the structure.

Safe pattern for code files: ^r?n only.

If you need to remove whitespace-only lines from code too, do a second pass with ^[ t]+$r?n and review each match manually using Find Next before committing to Replace All.

What Is the Difference Between Empty Lines and Blank Lines in Notepad++?

maxresdefault How to Remove Empty Lines in Notepad++

An empty line contains only a newline character (n on Unix, rn on Windows). A blank line contains spaces or tabs before the newline. They look identical in the editor but require different regex patterns to delete.

This distinction matters more than most tutorials acknowledge. A file exported from Excel, for example, frequently contains rows of spaces that appear as blank lines but are not empty.

Line TypeActual ContentPattern to Remove
Empty line\n or \r\n only^\r?\n
Blank line (spaces)One or more spaces + newline^\s*$\r?\n
Blank line (tabs)One or more tabs + newline^[ \t]*\r?\n
Mixed whitespaceSpaces and tabs + newline^\s*$\r?\n

To reveal what’s actually on a line, go to View > Show Symbol > Show All Characters. Spaces appear as dots, tabs as arrows. If you see either before the line-ending marker, you have a blank line, not an empty one.

How Does the Replace All Method Handle Windows vs. Unix Line Endings?

maxresdefault How to Remove Empty Lines in Notepad++

Windows files use rn (CRLF) as the line ending. Unix and Mac files use n (LF) only. The pattern ^r?n handles both because the r? makes the carriage return optional.

Using ^n alone on a Windows file leaves behind stray r characters after each deletion. Those are invisible in the editor but cause problems in parsers, compilers, and tools that consume the file downstream.

How to Check and Fix Line Endings Before Running Regex

Check current format: View > Show Symbol > Show All Characters reveals CR LF or LF markers at each line end.

Convert before running regex: Edit > EOL Conversion > Convert to Unix Format (LF) standardizes the file to n only. Then ^n works cleanly.

Notepad++ versions prior to v7.x handled EOL detection inconsistently. On v8.x (current), the editor detects line ending format automatically on file open and displays it in the status bar at the bottom right.

If you’re handling files from multiple sources — Windows batch exports, Unix server logs, or Git-managed repositories — it’s worth standardizing line endings first. The source control management layer in Git, for instance, can silently convert line endings on checkout, which changes what your regex actually needs to match.

How Do You Remove Empty Lines in Notepad++ Using a Macro?

maxresdefault How to Remove Empty Lines in Notepad++

Macros let you record the Find and Replace operation once and replay it on demand. This saves time when you clean the same type of file repeatedly across multiple sessions.

The recording captures your exact keystrokes inside the Find and Replace dialog, including the regex pattern, the empty Replace field, and the Replace All click. Every detail gets stored.

How to Record, Save, and Reuse the Macro

Recording steps:

  1. Go to Macro > Start Recording
  2. Open Find and Replace (Ctrl+H)
  3. Set Search Mode to Regular expression
  4. Enter ^r?n in the Search field, leave Replace empty
  5. Click Replace All, close the dialog
  6. Go to Macro > Stop Recording
  7. Go to Macro > Save Current Recorded Macro, assign a name and optional shortcut

Saved macros are stored in shortcuts.xml, located in %AppData%Notepad++. They persist across sessions and survive Notepad++ updates as long as that file is not overwritten.

One limitation: the built-in macro recorder does not batch across multiple open files natively. For that, go to Macro > Run a Macro Multiple Times and set a repeat count, but this applies only to the currently active file.

How Do You Batch Remove Empty Lines Across Multiple Files in Notepad++?

maxresdefault How to Remove Empty Lines in Notepad++

Notepad++ v8.4 added Replace support inside Find in Files (Ctrl+Shift+F). Earlier versions only supported read-only search across files, with no replace capability.

On v8.4 and later, you can set a directory path, enter a file filter like .txt or .csv, switch to Regular expression mode, enter ^r?n in the Find field, leave Replace empty, and click Replace in Files. The editor modifies every matching file in that folder.

What Are the Risks of Batch Empty Line Removal

Batch replacements in Notepad++ are irreversible once files are saved. There is no undo for changes written to disk across multiple files.

Before running any batch replace:

  • Back up the entire folder first
  • Test the regex on a single file to confirm it behaves correctly
  • Verify the file filter is specific enough (avoid . on mixed directories)

For large-scale cleanup across hundreds of files, a command-line approach using PowerShell or sed gives more control and a dry-run option before writing changes. Notepad++ Find in Files is reliable for folders of 10-50 files. Beyond that, script it.

How Do You Remove Empty Lines in Notepad++ Using the TextFX Plugin?

TextFX is a legacy plugin that predates Notepad++’s improved native regex engine. It was the standard method for removing blank lines in Notepad++ versions 5.x and 6.x, before reliable regex replace existed in the core editor.

The function is at TextFX > TextFX Edit > Delete Blank Lines. One click, no regex required.

Why TextFX Is No Longer the Recommended Method

TextFX is not available through Plugins Admin in Notepad++ v7.6 and later. The plugin was removed from the official plugin repository because it was no longer maintained and caused instability on 64-bit builds.

Installing it on current versions requires manually placing the DLL in the plugins folder, which most users should skip entirely. The native regex approach does the same job without compatibility risk.

One actual limitation of TextFX that still matters for historical context: it only removed lines with zero characters. It did not handle whitespace-only lines. The native regex patterns covered in the first section do both.

If you are on a legacy install and specifically need TextFX, check whether you are running a 32-bit build of Notepad++ v6.x or earlier. That is the only scenario where TextFX installs cleanly. On anything current, use Ctrl+H with regex instead. You can compare how Notepad++ stacks up against alternatives in the Notepad++ vs Notepad breakdown or the Notepad++ vs VS Code comparison.

How Do You Remove Empty Lines in Notepad++ Using Column Editor or Scripts?

maxresdefault How to Remove Empty Lines in Notepad++

For files over 100,000 lines, or when empty line removal is part of a repeatable automated pipeline, the Python Script plugin gives more precision than the Find and Replace dialog.

The plugin is available through Plugins > Plugins Admin on Notepad++ v7.6+. Search for “PythonScript,” install it, then access the editor at Plugins > Python Script > New Script.

How to Write a Python Script to Remove Empty Lines

Basic script (3 lines):

text = editor.getText() cleaned = "n".join(line for line in text.split("n") if line.strip()) editor.setText(cleaned) `

This reads the full buffer, filters out lines that contain only whitespace, and writes the result back. It handles both empty lines and blank lines in one pass.

Save the script with a name, then assign a keyboard shortcut under Plugins > Python Script > Configuration. After that, the cleanup runs in one keypress.

What Column Mode Can and Cannot Do for Line Removal

Column mode (Alt+click and drag): selects a vertical block of characters. It does not remove entire lines.

It is useful for deleting a specific character column from a range of lines — for example, removing a leading pipe character from a markdown table. For empty line deletion, column mode adds no value over the regex method.

Where column mode actually helps is when you want to inspect whitespace patterns across many lines at once. Selecting column 1 across 50 lines shows immediately whether those positions contain spaces or are truly empty. That narrows down which regex pattern you need before you run Replace All.

Developers familiar with the VS Code environment will notice that Notepad++’s column mode works similarly to VS Code’s multi-cursor column selection, though without the live preview of what the selection will delete.

What Are the Regex Patterns for Removing Empty Lines in Notepad++?

maxresdefault How to Remove Empty Lines in Notepad++

Notepad++ uses the Boost regex library (v1.90 as of v8.9.1), which is PCRE-like but not identical to standard PCRE. Patterns tested on regex101.com using the PCRE flavor may behave differently inside Notepad++ (Notepad++ User Manual, 2024).

The 4 patterns below cover every real-world empty line removal scenario.

PatternWhat It RemovesWhen to Use
^\r?\nZero-character lines (CRLF + LF safe)Default choice for most files
^\s*$\r?\nEmpty + whitespace-only linesCSV exports, copy-paste content
^(\h*\R)+Blank lines, all EOL types including old Mac \rMixed-origin files
\R\R\K\R+Surplus blank lines only (keeps one)Prose documents, markdown files

The R syntax in Boost regex matches any line ending: rn (Windows), n (Unix), and r (old Mac). It is more portable than r?n when files come from multiple platforms (Notepad++ Community Forum).

What “Extended” vs. “Regular Expression” Mode Means

Two different modes, two different behaviors:

  • Extended mode — interprets escape sequences like n and t, but does NOT process regex metacharacters like ^, $, or s
  • Regular expression mode — full regex engine, processes all metacharacters and anchors

Empty line removal requires Regular expression mode. Switching to Extended by mistake is the most common reason the pattern runs but deletes nothing.

Common Mistakes That Break Empty Line Patterns

Search Mode left on “Normal” is the single most frequent error. The pattern ^r?n in Normal mode is treated as a literal string search, not a regex, and finds zero matches.

Three other failure points:

  • Using ^n on a Windows file with CRLF endings (leaves stray r characters)
  • Using the RRKR+ surplus pattern with the step-by-step Replace button -- this pattern only works correctly with Replace All
  • Testing a pattern on regex101.com set to PCRE flavor and expecting identical results in Notepad++ (Boost and PCRE are similar but not the same)

If a pattern worked before and suddenly stops, check whether a Notepad++ update changed the Boost library version. The library updated from v1.78 (v8.2) to v1.80 (v8.4.7) to v1.85 (v8.7.9) to v1.90 (v8.9.1), each with minor behavioral differences on edge-case patterns.

How Do You Undo a Remove Empty Lines Operation in Notepad++?

maxresdefault How to Remove Empty Lines in Notepad++

Ctrl+Z undoes Replace All as a single operation while the file remains open in the current session. One keypress reverses every deletion made by Replace All, regardless of how many lines were removed.

Undo history in Notepad++ is held in memory by the Scintilla editor component. It does not persist to disk (Notepad++ Community Forum, 2017).

When Undo Is Not Available

3 situations where Ctrl+Z will not recover deleted lines:

  • The file was saved after Replace All ran
  • Notepad++ was closed and reopened (session restore does not include undo history)
  • The file was modified by an external program and reloaded (answering “Yes” to the reload prompt clears undo history)

For batch Replace in Files operations, there is no undo at all. Changes are written directly to disk across all affected files.

Best Practice Before Running Replace All

Save As first. Go to File > Save As and write a backup copy with a date suffix before running any destructive regex operation.

Alternatively, use Edit > Copy All (or Ctrl+A then Ctrl+C) to copy the full file content to the clipboard. If the regex goes wrong, paste it back into a new file immediately.

For files managed in a Git repository, commit the file before editing. That gives you a clean rollback point without relying on Notepad++’s in-memory undo. The basics of Git cover exactly this kind of pre-edit commit workflow.

How Do You Remove Empty Lines in Notepad++ for CSV or Structured Data Files?

Empty lines in CSV files cause parser errors in most downstream tools. Python’s pandas library, for instance, raises a ParserError: Error tokenizing data when it encounters unexpected blank rows mid-file (Towards Data Science, 2024).

The same ^r?n pattern works on CSV files, but 3 additional checks matter before and after running it.

Encoding Checks Before Cleaning a CSV

Check encoding first: go to Encoding in the menu bar and verify whether the file is UTF-8 or UTF-8-BOM.

A UTF-8-BOM file has a 3-byte sequence at the start of the file that some parsers treat as a blank first character. Removing empty lines from a BOM file does not remove the BOM. If your CSV parser is throwing errors on line 1 after cleanup, the BOM is likely the cause.

Convert to UTF-8 (no BOM) via Encoding > Convert to UTF-8 before running Replace All on any CSV intended for database import or pipeline ingestion.

Verifying Line Count Before and After

The Status Bar at the bottom of the Notepad++ window shows total line count in real time.

Workflow:

  1. Note the line count before running Replace All
  2. Run Replace All with ^r?n
  3. Check the new line count in the Status Bar
  4. Verify the difference matches your expected number of removed blank lines

If the count dropped more than expected, Ctrl+Z immediately. A count drop larger than the number of visible blank lines means the pattern matched lines it should not have, which happens most often when the file uses s patterns on structured data with intentional spacing.

Why CSV Files Need Extra Caution vs. Plain Text

Row integrity in CSV files depends on exact line count. A blank line mid-file shifts every subsequent row index by one.

Remove empty lines from CSVs in isolation:

  • Never batch-process CSV files alongside mixed file types in Find in Files
  • Always verify the column count on the first 5 rows after cleanup using a second open tab
  • Use the Compare Two Files feature in Notepad++ to diff the original and cleaned version before replacing the original

The ComparePlus plugin (available via Plugins Admin for Notepad++ v8.4.2+) adds an “Ignore Empty Lines” toggle to the comparison view. That lets you confirm the only differences between your original and cleaned CSV are the removed blank rows, and nothing else changed.

Developers who also work in VS Code can run the same pre-cleanup diff using the Find and Replace in VS Code, which offers a live preview of regex match results before committing any change, a feature Notepad++ does not have natively.

FAQ on How To Remove Empty Lines In Notepad++

What is the fastest way to remove empty lines in Notepad++?

Open Find and Replace with Ctrl+H, set Search Mode to “Regular expression,” enter ^r?n in the Search field, leave Replace empty, and click Replace All. Done in under ten seconds on any file size.

What regex pattern removes blank lines in Notepad++?

Use ^r?n for truly empty lines. For lines containing only spaces or tabs, use ^s$r?n instead. The difference matters -- CSV exports and copy-pasted content almost always have whitespace-only lines, not empty ones.

Why is my regex pattern not working in Notepad++?

Search Mode is almost certainly set to “Normal” instead of “Regular expression.” That treats ^r?n as a literal string. Switch the mode in the Find and Replace dialog before running the search.

How do I remove blank lines without deleting indented code?

Stick to ^r?n only. The pattern ^s$r?n matches lines containing only whitespace, which includes intentional indentation in Python, YAML, and similar files. Wrong pattern here breaks file structure.

Can I remove empty lines from multiple files at once in Notepad++?

Yes. Use Find in Files (Ctrl+Shift+F) with Replace support, available in Notepad++ v8.4 and later. Set a folder path, apply a file filter like .txt, enter the regex, and click Replace in Files. Back up first.

Does Notepad++ have a built-in option to delete blank lines without regex?

Yes. Go to Edit > Line Operations > Remove Empty Lines. It removes zero-character lines instantly with no regex required. It does not remove whitespace-only lines, so it is not suitable for all file types.

How do I undo a Remove Empty Lines operation in Notepad++?

Press Ctrl+Z immediately. Notepad++ treats Replace All as a single undoable action. Once you save the file or close the editor, undo history is gone. For batch file operations, there is no undo at all.

What is the difference between empty lines and blank lines in Notepad++?

An empty line holds only a newline character. A blank line holds spaces or tabs before the newline. They look the same visually. Use View > Show Symbol > Show All Characters to see the difference before choosing a pattern.

How do I remove empty lines from a CSV file in Notepad++?

Run ^r?n via Find and Replace with regex mode active. Check encoding first -- UTF-8-BOM files need conversion to UTF-8 before cleanup. Verify line count in the Status Bar before and after to confirm only blank rows were removed.

Can I use a macro to remove empty lines automatically in Notepad++?

Yes. Record the Find and Replace steps under Macro > Start Recording, then save the macro with a name and shortcut. Stored in shortcuts.xml, it persists across sessions and runs the entire blank line removal in a single keypress.

Conclusion

This conclusion is for an article presenting every practical method for blank line deletion in Notepad++, from quick regex patterns to batch file cleanup and Python Script automation.

The Find and Replace dialog handles most cases. ^r?n for zero-character lines, ^s$r?n` when whitespace-only lines are involved.

For structured data like CSV files, verify encoding and check line count in the Status Bar before and after running Replace All.

Macros and the Python Script plugin cover repeatable workflows and large-file scenarios where manual regex entry gets tedious.

Pick the method that fits the file. Back up before any batch replace. The rest is just choosing the right pattern.

50218a090dd169a5399b03ee399b27df17d94bb940d98ae3f8daff6c978743c5?s=250&d=mm&r=g How to Remove Empty Lines in Notepad++
Latest posts by Bogdan Sandu (see all)

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.