How can I remove the ^M from my file in sublime text 3?
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.
You can use dos2unix
command in linux (package dos2unix) or change line endings in Sublime Text under menu item View / Line Endings.
^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 asdos2unix
) 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'