Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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++?

share|improve this question
2  
And why the down voting ? simple clear question –  Moudiz Jul 19 '13 at 11:02
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

3 Answers 3

up vote 11 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.
share|improve this answer

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

enter image description here

share|improve this answer
    
So cool! I never noticed there is so many edit options in Edit menu. Thanks! –  klerik Jul 16 at 14:53

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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