Deleting double blank lines or more in Notepad++ while retaining single blanks

I am trying to delete blank lines in a document, but wish to keep single blanks intact. For example:

line 1
line 2
line 3
line 4

Must delete find and replace to keep a single blank line between all:

line 1
line 2
line 3
line 4

Any help is appreciated. Thanks.

3 Answers

  • In the Replace dialog (Ctrl-H), select Extended Search Mode.
  • For the Find what text, enter (for Windows carriage-return/line-feed convention to mark end of line):

    \r\n\r\n

  • For the Replace with text, enter

    \r\n

Each time you click replace All, double CR/LF's will be converted to single, or quadruple CR/LF's to double.

The characters to enter may be changed in different circumstances, e.g. if a line has a single space, or if the CR/LF convention differs, as in Mac and Linux OS's.

Windows solution: you could use this autohotkey script on notepad++.

Bonus: it will work on notepad++ plus everywhere else on your computer.

You can call it with a shortcut (alt+space here):

^!Space:: clipboard = Send, ^a Send, ^c ClipWait ClipBoard := RegExReplace(ClipBoard, "\R(?=\R{2,})") sleep 100 Send, ^v return

This will replace all linebreaks that are followed by 2 linebreaks, living only 2 linebreaks.

  • Ctrl+H
  • Find what: \R+(?=\R{2})
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

\R+ : 1 or more any kind of linebreak (i.e. \r, \n, \r\n)
(?= : positive lookahead, a zero-length assertion that make sure we have after \R{2} : 2 linebreaks
) : end lookahead

Result for given example:

line 1
line 2
line 3
line 4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like