Sublime Text 2: How to delete blank/empty lines
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).
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+$
There are also some ST2/ST3 Plugins for such tasks. I do like these two:
- Delete Blank Lines (also available via Package Control)
- Trailing Spaces (also available via Package Control)
The first one has two methods for removing empty/unnecessary lines. One of them called Delete Surplus Blank Lines
which is cool. It removes only those lines that are followed by another empty line
A Find/Replace solution:
Regex Find:\s+
Replace with: //single space