The Computer Oracle

How can I remove the ^M from my file in sublime text 3?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay

--

Chapters
00:00 How Can I Remove The ^M From My File In Sublime Text 3?
00:29 Answer 1 Score 8
01:14 Answer 2 Score 17
01:28 Accepted Answer Score 3
02:23 Answer 4 Score 26
03:16 Thank you

--

Full question
https://superuser.com/questions/1217622/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#git #ubuntu1404 #sublimetext3

#avk47



ANSWER 1

Score 26


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.




ANSWER 2

Score 17


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




ANSWER 3

Score 8


^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'



ACCEPTED ANSWER

Score 3


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

Installation

  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:

/home/YOUR_USERNAME/.config/sublime-text-3/Packages

Usage

  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.