If the file size is small enough, you can remove the empty lines manually.
If a file contains a thousand lines, You have to use find blank lines and remove empty lines.
Manually doing it is extremely difficult and time-consuming.
Sublime Editor provides the following three ways options
- Use the Find and Replace feature to search for and replace text with regular expressions.
- Permute Lines unique option.
- Trimmer package
For example, a text file contains
Eric
Andrew
Eric
John
Matt
John
After trimming and removing empty and blank lines with characters, The output is
Eric
Andrew
Eric
John
Matt
John
How to Remove Empty or Blank Lines in Sublime 3 Editor?
There are multiple ways you can remove the lines.
Use Permute Lines Operations
Open the file in Sublime Editor.
Select Edit> Permute Lines > Unique
It removes the empty or blank characters as well as duplicate lines from the entire file
The only disadvantage of this approach is, It removes duplicate lines, including blank lines.
- Find and Search with regular expression
Find and search is an inbuilt feature in the editor.
Open
File
>Replace
or use ShortcutCtrl + H
in Windows,⌘ + Alt + F
on Mac.It opens the
Replace
Window bottomSelect and type below
Find
with^[\s]*?[\n\r]+
- for blank lines and blank character linesReplace
space- Check
Wrap
icon - Select Search Mode as
Regular Expression
or ShortCutAlt + R
in Windows,⌘ + Alt + R
in Mac - Click on the
Replace All
button.
It removes empty and blank lines from the file.
Use the Trimmer package Trimmer is a custom package that deletes empty and blank lines for an entire file or selection of a file apart from other things such as removing end and beginning spaces and tabs and deleting comments.
Install the Trimmer Package. Please see how to install packages to Sublime text Once Trimmer package control is installed, Go to the next steps.
Select
Tools
Menu +Command palette
or use following shortcut commands- Windows: hotkeys: Ctrl + Shift + P
- Mac: shortcuts: ⌘ + Shift +P
It opens the
command palette
and typetrimmer
in the search box and select theTrimmer: Delete empty Lines
optionIt removes empty lines and blank characters in empty lines.