Atom text editor remove trailing whitespace on save

48,746

Solution 1

Under your Atom Preferences go to Packages tab and search for whitespace. Click on the whitespace package and uncheck Ensure Single Trailing Newline option

enter image description here

Solution 2

On global level this can be changed using settings in Whitespace package, but if you want to disable it for a specific language you have to use syntax-scoped properties in your config.cson.

'.text.html.php': # php overrides
  whitespace:
    ensureSingleTrailingNewline: false
    removeTrailingWhitespace: false

'.source.ruby': # ruby overrides
  whitespace:
    ensureSingleTrailingNewline: false
    removeTrailingWhitespace: false

To see the scope of language go to Packages tab and search for your language.

Click on the settings of the language package and you can see the scope:

Solution 3

Go to packages and find "whitespace", go to it's settings and uncheck the last checkbox.

Settings Settings screenshot

Checkbox Checkbox screenshot

Share:
48,746
Nasif Md. Tanjim
Author by

Nasif Md. Tanjim

I am a software developer. I work in Java related technologies including Android. I also have modest skill in frontend technologies.

Updated on July 25, 2020

Comments

  • Nasif Md. Tanjim
    Nasif Md. Tanjim almost 4 years

    I use Sublime text. Now I am trying Atom. When I save any file in sublime text it does not include any trailing blank line. But saving any file in Atom leaves a trailing blank line. How do I force Atom not to leave trailing white spaces?

  • Gagan
    Gagan almost 8 years
    I think its even better if we unckeck "Ignore whitespace On current line". This will remove the trailing whitespace of current line at the time when file is saved.
  • jcalfee314
    jcalfee314 almost 7 years
    Could this message get any more cryptic? Lol - I'm just over-joyed to have Atom mangle a long file's diff because another dev left some trailing spaces only to find that it is not possible to find this setting by name. Few.. Anyone notice that the name changed from Package to Settings?
  • bluecollarcoder
    bluecollarcoder almost 7 years
    Maybe this is a new setting, but there is a Remove Trailing Whitespace checkbox at the bottom of the settings section. Unchecking it preserves all trailing whitespaces.
  • ssc
    ssc over 6 years
    Your answer is even more detailed than the official docs at github.com/atom/whitespace, thanks for taking the time to put this up! :-) I would love to configure atom this way, but I can't get it to work, atom keeps turning two trailing newlines into a single one in my jinja2 files. Scope is .text.html.jinja, config matches yours, but doesn't work. Global it is then :-(
  • Steve
    Steve over 5 years
    The image showing how to find the scope was particularly useful. I've since also found the scopes listed in the grammar selector (by default to the right of the line endings, line number and encoding at the bottom of the window, or with the default shortcut ctrl+shift+L).
  • Matt Kleinsmith
    Matt Kleinsmith over 3 years
    File --> Settings --> Packages
  • Manngo
    Manngo about 2 years
    Do you have any idea how hard it is to read your screenshot? Us a dark theme in your own work if you must, but a light theme makes a much more readable image.