Suppose I have these lines:

A

B

C

D

E

I want remove empty lines, and the spaces before the letter too, like this:

A
B
C
D
E

How can I achieve this in Notepad++?

  • 1
    no idea, perfectly fine question imo. btw can you check if the formatting is correct for your spaces. Is there meant to be four spaces before a character (if so, add 4 more per line so the site's formatting takes this into account) – Jay Jul 19 '13 at 11:09
up vote 56 down vote accepted

To get rid of leading space(s) and all empty lines (even if the empty line contains spaces or tabs)

  1. Go to Search -> Replace
  2. Select "Regular expression" under Search mode.
  3. Use ^\s* for "Find what" and leave "Replace with" blank.
  4. Click Replace all

Regex explanation:

  • ^ means beginning of the line
  • \s* means any number (even 0) of whitespace characters. Whitespace characters include tab, space, newline, and carriage return.
  • What would you search for to remove trailing white spaces if ^\s* is beginning of line? – Aaron Dec 12 '14 at 16:04
  • 1
    An alternativeo to \s* would be \s+ for one or more white spaces? – ian_scho Sep 8 '15 at 11:06
  • 2
    @Aaron: Search for \s+$ to remove trailing whitespace. – palswim Oct 15 '15 at 21:16
  • 1
    -1 This also deletes the indent – Black Jan 6 at 12:27

Edit -> Line Operations -> Remove Empty Lines or alternatively: Edit -> Line Operations -> Remove Empty Lines (Containing Blank characters)

enter image description here

  • 3
    So cool! I never noticed there is so many edit options in Edit menu. Thanks! – icl7126 Jul 16 '14 at 14:53
  • 1
    This is what most people are looking for when then come to StackOverflow for this question, unfortunately the "\r\n" and "^\s*" answers are "Cooler", takes me 5 minutes to find this answer with Google. Those other answers are kind of self explanatory (with a little knowledge of regular expressions and escape chars), this in the one that actually saves you time... – BillyNair Mar 18 '15 at 3:09

Go to Edit > Line Operations > Remove Empty Lines

  • No reason to downvote this. It is a perfectly valid answer. – DavidPostill Jul 15 '16 at 19:33

The easy way would be select everything (Ctrl+A), go to Edit>Blank Operation>Trim Trailing Space.

This should remove all the spaces in between.

  • Exactly what I needed, thanks!! – SamAndrew81 Apr 26 at 16:34

You could use a simple regular expression search and replace.

  1. Click Ctrl+H for the Replace dialog
  2. Make sure you select 'Regular expression' option
  3. Find what: ____(.)\r_ (swap _ with space, as it doesn't format right on this site)
  4. Replace with: \1

Change the spaces as you need because I think this site is not showing the exact spaces you need.

Find and Replace dialog in Notepad++

I recommend tailor making your regular expression using this tutorial and this cheat sheet.

Press Ctrl+H to open Find and Replace dialog Box, and enter like below.

  1. Type \r\n\r\n in Find what
  2. Type \r\n in Replace with
  3. Select Extended in Search Mode
    [\r -> Carriage Return & \n ->Line Feed] It will even removes uneven line spaces.Just continue clicking REPLACE ALL till you attain the expected result. Hope this helps!

Copy 2 blank spaces (Ctrl+C), search and replace (Ctrl+H), paste in the Find field and select Replace. If you have the same character with a blank space behind or in front, copy the character with the blank and replace it with the same character without the blank.

No complicated commands, which, by the way, didn't work for me.

  • 1
    This sound like removing spaces, not line feeds. – Jan Doggen Dec 5 '14 at 11:23

Go to Edit > Blank Operations > Remove Unnecessary Blank and EOL

  • -1. This places everything in a single line. – Kamil Maciorowski Nov 10 '17 at 7:33

protected by Community Sep 21 at 8:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.