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?
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?
Select the text
Press:
Make sure you have selected 'regular expression' by pressing:
Find what: ^\n
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:
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
Don't even know how this whole thing works, but I tried
^\s*$
and didn't work (leaving still some empty lines).
This instead ^\s*
works for me
{sublime text 3}
I had to use:
replace \n^\s*\n with \n
The https://github.com/NicholasBuse/sublime_DeleteBlankLines plugin did nothing at all.
Simpler than I thought. Ctrl
+ A
Followed by Ctrl
+ H
Then Select Regular Expression .*
. Replace \n\n
with \n
. Voila!
You are looking for this:
^\n|^\s+$
it will not delete the line, if there is content with white space or tabs in front>
e.g.:
these will not be deleted: ...space... abc
...tab... abc
this will:
...space... ...nothing else...
...tab... ...nothing else...
Using multiple selections: select one pair of line breaks, then use Quick Find All (Alt+F3), or Quick Add Next (Ctrl+D) repeatedly, to select them all; then hit Enter to replace them with single line breaks.
The Comments of @crates work for me,
Step 1: Simply press on ctrl+H
Step 2: press on RegEX key
Step 3: write this in the Find: ^[\s]*?[\n\r]+
Step 4: replace all
Another way, you can use the command line cc.dbl
of ConyEdit (a plugin) to delete blank lines or empty lines.
There's also "Join lines". If on OSX, select all your text, and press CMD-J a few times, and it will collapse your selection by line, removing the line breaks.
Edit: This approach will leave you with everything on one line, which is not what you asked for.
For those who are curious of sublime text editor, the unofficial-documentation may be interesting!
There is a wonderful package (for Sublime 2 & 3) called 'Trimmer' which deletes empty lines. It also does many other useful things.
Refer this: https://packagecontrol.io/packages/Trimmer
Using find / replace, try pasting a selection starting at the end of the line above the blank line and ends at the beginning of the line after the blank. This works for a single blank line. You can repeat the process for multiple blank lines as well. CTRL-H, put your selection in the find box and put a single newline in the replace box via copy/paste or other method.
In my case some empty lines contained the unicode character zero width space (U+200b). To rid empty lines, including the ones with this unicode character:
\s\x{200b}|^\s
If ^\n
does not work properly ===> try .*[^\w]\n