Sublime Text 2: How to delete blank/empty lines

279

Let's say I had a text file with the following nine lines:

foo

bar

baz

qux

quux

How can I use Sublime Text 2 to remove all four of the blank/empty lines, leaving only five lines?

This question is tagged with sublimetext2

~ Asked on 2012-08-17 15:48:12

The Best Answer is


674

Select the text

Press:

  • Ctrl + H on PC, or
  • Command + Alt + F on Mac or
  • Click Find->Replace.

Make sure you have selected 'regular expression' by pressing:

  • Alt + R on PC or
  • Command + Alt + R on Mac or
  • Click .* in the Find box.

Find what: ^\n or ^(\r|\n\r?)

Replace With: (nothing, leave in blank).

~ Answered on 2012-08-17 16:22:52


69

The regexp in Hugo's answer is correct when there is no spaces in the line. In case if there are space regexp can be ^\s+$

~ Answered on 2013-02-15 10:58:33


Most Viewed Questions: