Deleting all empty lines


#1

Hi guys,

it’s possible delete all empty line, in a file, like sublime text?

example: link to example

Thanks everyone


#2

Quick n’ dirty hack.
Add this in your init.coffee file:

atom.commands.add 'atom-workspace', 'lines:delete-whitelines', ->
  buffer = atom.workspace.getActiveTextEditor().getBuffer()
  newLines = buffer.getLines().filter (line) -> line isnt ''
  buffer.setText newLines.join '\n'

You can invoke it from the command palette, it will do the trick for the currently selected buffer. It could be optimized for sure, I can think a couple of solutions using regex.


#3

The regex version replaces any sequence of two newline chars with just one newline.

atom.commands.add 'atom-workspace', 'lines:delete-whitelines-regex', ->
  buffer = atom.workspace.getActiveTextEditor().getBuffer()
  buffer.replace /\n\n/g, '\n'

Speaking of which, if you don’t need the command pronto, you could run a search in the buffer using the regex filter, then replacing \n\n with just \n.


#4

try delete-whitelines package, https://atom.io/packages/delete-whitelines


#5

It appears that this is a duplicate of a previous topic:

We like to unify similar discussions under one topic so that people don’t have to read a bunch of different threads to get the whole story. Please continue the discussion there. I’ll be closing this topic as duplicate.


#6

This topic was automatically closed after 12 hours. New replies are no longer allowed.