Sublime Text: Remove Empty Lines

If you try to figure out how to remove the blank lines in a document, i.e. the lines that contain only spaces, tabs or the newline characters, you should know that in almost any IDE, like a Sublime Text, this can de done really simple.

The Sublime Text, like the other IDEs, has the ability to delete empty lines in the “Replace” operation by using the “Regular expression”.

This short note shows how to remove empty lines in the Sublime Text.

Cool Tip: How to add a newline at the EOF on save in Sublime Text! Read more →

Remove Empty Lines in Sublime Text

Here is a step by step instruction for how to remove empty lines in the Sublime Text editor:

  1. Go to the FindReplace
    – or – press the Ctrl + H on Windows/Linux or ⌘ Cmd + Alt + F on Mac
  2. Select the ‘Regular expression‘ by clicking on the .* button in the Find box
    – or – press the Alt + R on Windows/Linux or ⌘ Cmd + Alt + R on Mac
  3. In the Find field, type in:
    ^\n to delete empty lines excluding the ones that contain whitespaces:
    – or – ^(\r|\n\r?) to delete empty lines including ones with whitespaces:
  4. Leave the Replace field empty
  5. Click on the Replace All button

Cool Tip: How to enable spell checking in Sublime Text! Read more →

One Reply to “Sublime Text: Remove Empty Lines”

  1. Ctrl+H -> Select the ‘Regular expression‘ -> find “^$” -> find all -> press del

Leave a Reply