Home / Guides

Remove Empty Lines From Text in Word, VS Code and More

Published 2026-11-07

To remove empty lines, search for blank lines and replace them with nothing. In Word, replace ^p^p with ^p; in Notepad++, use Edit > Line Operations > Remove Empty Lines; in a code editor, use a regular expression for a line with nothing on it. This guide shows how to remove empty lines in each tool, how to keep a single blank line between paragraphs instead, and why a line that looks empty sometimes refuses to go.

What counts as an empty line

People use "empty line" for three different things, and the right method depends on which one you have.

KindWhat is in the lineCaught by
Truly emptyNothing between two line breaksEvery method below
Whitespace onlySpaces or tabsMethods that allow for whitespace, such as ^\s*$
Looks empty, is notA hidden character such as a zero-width spaceOnly after removing the hidden character

If your goal is the opposite, joining lines inside a paragraph, that is a different job. See how to remove line breaks.

Remove empty lines in Microsoft Word

In Word, a blank line is an empty paragraph, and a paragraph mark is written ^p in the Find box.

  1. Press Ctrl + H to open Find and Replace.
  2. In Find what, type ^p^p. In Replace with, type ^p.
  3. Click Replace All, then click it again until Word reports zero replacements. Each pass removes one empty paragraph from every run.

This deletes every blank paragraph, including the ones that separate paragraphs on purpose. If you want visual gaps between paragraphs, set them with paragraph spacing (Home tab, Paragraph settings, Spacing After) and leave the empty lines out.

If a gap survives, it may be a manual line break, which is written ^l, or a paragraph that holds a space. Show the formatting marks with Ctrl + Shift + 8 to see which.

Remove empty lines in Notepad++

Notepad++ has two ready-made commands under Edit > Line Operations:

Select a range first if you want to limit the change to part of the file.

Remove empty lines in Visual Studio Code

Open Replace with Ctrl + H (Option + Cmd + F on a Mac), click the .* button to switch on regular expressions, and use one of these:

GoalFindReplace with
Delete all empty and whitespace-only lines^\s*$\nnothing
Delete only truly empty lines^\nnothing
Keep one blank line, remove the rest\n{3,}\n\n

In the first pattern, ^ and $ mark the start and end of a line, and \s* allows any spaces or tabs in between. The same patterns work in most editors with regular expression search, though the handling of the line break at the end can differ, so try them on a copy first.

Remove empty lines in Google Docs

Docs has no command for removing empty paragraphs. Two practical routes:

Choose View > Show non-printing characters to see where the empty paragraphs are.

Remove empty rows in Excel

  1. Select the column that decides whether a row is blank.
  2. Choose Home > Find & Select > Go To Special, tick Blanks and click OK.
  3. Choose Home > Delete > Delete Sheet Rows.

Be careful: the command deletes every row where the selected column is empty, even if other columns on that row contain data.

Command line and scripts

# Delete empty and whitespace-only lines
sed '/^[[:space:]]*$/d' input.txt > output.txt
grep -v '^[[:space:]]*$' input.txt > output.txt
awk NF input.txt > output.txt

# Squeeze runs of empty lines into one
cat -s input.txt > output.txt
# Python
lines = [line for line in text.splitlines() if line.strip()]
text = "\n".join(lines)

Python's strip() removes non-breaking spaces as well as ordinary ones, but not the zero-width space.

Why an empty line will not delete

What the AI Text Cleaner does with blank lines

The AI Text Cleaner collapses blank lines rather than deleting them all. With the option Collapse extra blank lines on (the default), any run of three or more line breaks, meaning two or more empty lines in a row, becomes a single empty line. One blank line between paragraphs is kept, which is usually what you want for readable text.

A few related behaviours:

Quick answers

How do I remove blank lines in Word? Replace ^p^p with ^p and repeat until nothing is left to replace.

How do I remove blank lines but keep paragraph breaks? Collapse runs of blank lines to one instead of deleting them all. In an editor, that is \n{3,} replaced by \n\n.

Why does the empty line come back after pasting? The source likely has spacing built in, such as paragraph margins rendered as blank lines. Clean the pasted text once it has arrived.

Squash runs of blank lines down to one. The Collapse extra blank lines option does that and strips trailing spaces, so lines that only held spaces count as empty too. Open the AI Text Cleaner

Related guides