Deleting all empty lines


Hi guys,

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

example: link to example

Thanks everyone


Quick n’ dirty hack.
Add this in your 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.


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.


try delete-whitelines package,


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.


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