Remove the empty lines of Sublime Text
Eliminate clutter & tidy up code with Sublime Text's Empty Line Removal feature. Example: Delete 6 lines with one shortcut!
Removing Empty Lines in Sublime Text
Sublime Text is a powerful text editor that can be used for many different tasks. One of the most common tasks is to remove empty lines in a text. This can be done in a few different ways.
The first way is to use the built-in feature of Sublime Text. To do this, you will need to open the document in Sublime Text, then press the “Ctrl + A” keys to select all the text, and then press the “Ctrl + Shift + K” keys to remove all empty lines.
Another way to remove empty lines is to use a regular expression. To do this, you will need to open the Find and Replace dialog box in Sublime Text. Then, you will need to enter the following regular expression in the Find field:
^s*r?
This expression will match any line that contains only whitespace characters. Finally, press the “Replace All” button to remove all the empty lines.
A third way to remove empty lines is to use a Python script. This can be done by creating a new Python file and adding the following code:
import sublime, sublime_plugin
class RemoveEmptyLinesCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
regions = view.find_all('^\s*r?$')
view.erase(edit, view.full_line(regions))
This script will remove all the empty lines in the document. To run the script, press the “Ctrl + B” keys to execute the script.
These are just a few of the ways to remove empty lines in Sublime Text. With a bit of practice, you should be able to quickly and easily remove any empty lines from your text documents.