18

Atom text editor adds this symbol to every empty line.

Any idea what and why?

enter image description here

rjdkolb
  • 10,377
  • 11
  • 69
  • 89
Ivan Chong
  • 181
  • 1
  • 3

4 Answers4

19

I'm on Ubuntu Linux and noticed the ^M (Carriage Return, Line Feed) during git diff.

Somehow CRLF was selected at the bottom of the status bar:

CRLF in Atom status bar

I simply clicked it and changed to LF:

LF in Atom Status Bar

It seems to be set on a file-by-file basis so will need to be changed for each problem file.


In my case somehow all the line endings had been changed so git diff was a sea of red. I used the following to identify 'real' changes:

git diff --ignore-space-at-eol

However, git commit would still bury the 'real' changes in commit history so I:

  1. ran git stash save
  2. changed line endings in atom
  3. ran git commit -am "fix line endings"
  4. ran git stash apply

Now the line endings are gone and commits can be made on a precise diff.

Pocketsand
  • 1,261
  • 10
  • 15
  • O man! you made may day. I/m not sure why it change to CRLF but anyway. thanks for this. – ngelx Mar 30 '17 at 05:28
4

Are you using Atom text editor under Windows?
Windows carriage return is \r\n while it is \n in Unix.
^M ( 0xD or \r ) is the carriage return character in Windows.
I think, that file was previously saved under Unix ( and already have \n on each line), so Atom is adding \r as required by Windows.

For more information you can see this and this

Community
  • 1
  • 1
Roman Zaitsev
  • 1,328
  • 5
  • 20
  • 28
  • 5
    Atom will show which line ending it is using at the bottom right of the status bar. See the plugin [documentation](https://github.com/atom/line-ending-selector). Changing it there will modify line endings for that file. In `Settings > Packages > line-ending-selector` you can set the default line ending for new files as well. – David Ulrich Jan 25 '16 at 08:28
  • From @DavidUlrich's comment, i dig abit into the package. From the above exercise, I found that the files in the repo i was working on were all CRLF. I concluded that since the project was previously done by another developer, most likely, bless him, he was using windows. – Ivan Chong Jan 26 '16 at 07:58
3

Check your bottom of the editor which might have changed your file line endings.

Usually it is LF for Unix

enter image description here

and CRLF for windows

enter image description here

Praneeth
  • 902
  • 2
  • 11
  • 25
1

Most of the solutions I've found online involve using sed, vi, or emacs. I found a solution that works directly within Atom (and probably any text editor), no command line needed.

Select all of the returns, or get a selector at the beginning of every line then delete and hit return. It might take a second, but it will get rid of all of the ^M characters.

This will likely screw up your indenting, but you can auto-indent. This might not be efficient if you have multiple files you need to do this with, but it's a quick and dirty solution for just one file.

Wylliam Judd
  • 9,935
  • 2
  • 26
  • 36