When I do a git diff in my branch I see that line endings have the characters ^M:

^M Line Endings

I want to replace these with Unix line endings before committing my changes.

I am using Ubuntu 14.04, git and sublime text 3.

I am looking for a way to change line endings in sublime text 3 not using other utilities or commands.


5 Answers 5


This can be done without a plugin via the menu at the top or though the statusbar (but you need to enable the feature).

To change it through the menu at the top click View -> Line Endings -> Select desired line ending type.

To enable this through the status bar: Click Preferences -> Settings Then add "show_line_endings": true, somewhere between the {} brackets on the right-hand side. Finally, save your changes.

This enables a small section on the right of the status bar that shows up at the bottom. It tells you the current EOL encoding and by clicking the box and selecting a different type it changes the files EOL character for you.

Another helpful option is file encoding which can be enabled in the statusbar as well by following the same setups above but also adding "show_encoding": true, between the {} marks.

  • This works specially when you are transfering files from windows to a server because in the server is harder to edit the file. Thanks Commented Aug 21, 2018 at 5:22
  • This should now be the accepted answer
    – lucas
    Commented Apr 6, 2020 at 13:51

You can use dos2unix command in linux (package dos2unix) or change line endings in Sublime Text under menu item View / Line Endings.

  • This answer remembered me of this tool, thank you, but unfortunately OP edited saying he want to modify line endings in sublime. Commented Feb 8, 2021 at 17:57

^M is \r (Control-M, or carriage return).

This is likely because the user who committed the file was using windows, which uses \r\n for its line endings. Linux uses only \n, hence you see the ^M at the end of the line.

You probably want to do one of the following:

  • 'Fix' the file to have \n line endings (using a tool such as dos2unix) and commit. In which case you'll be fighting with the other user unless you can get them to do the below.
  • Configure both of your git installations to handle line endings correctly for each environment - e.g: https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings
  • Configure Sublime to open the file with 'Windows line endings'

To whom may not want to install additional plugin to remove ^M new lines,

  1. In sublime text setting, add "trim_trailing_white_space_on_save": true, to auto remove space when saving. (This step might be optional)

  2. On the file you are opening, click right bottom corner of sublime text. Change Windows to Unix and save.

  1. ^M is gone. Enjoy.
  • Be aware that the line endings are not show in the status bar by default - you need to set the preference "show_line_endings" to 'true'.
    – jmc
    Commented Apr 13, 2021 at 8:31

I found a sublime text plugin that converts line endings in all open files to Unix/Windows/Mac OS 9.


  1. Open Sublime and go to Preferences > Browse Packages. This will open a window.
  2. Download or clone the contents of this repository to a folder named exactly as the package name into the Packages/ folder you opened in the previous step:



  1. Go back to sublime and open all the files that you want to convert.
  2. Once all of the files are open hit CTRL + SHIFT + P, and search and select “Line Ending to all view: Unix”.
  3. Hit CTRL + ALT + S to save all of the open files.
  • The repository has been deleted?
    – AnnanFay
    Commented Apr 11, 2019 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .