Sublime Forum

Sublime adds control-m in lines

#1

Hi,

I’m using sublimetext2 in windows with a git repo. In each line that I save with sublime when do a git diff, it’s show a new ending ^M

How can I configure sublime to not add this ^M ?

Thanks

0 Likes

#2

This is caused by the differences between Unix/Linux line-endings and windows line-endings. To terminate a line, Unix uses “\n” and windows uses “\r\n”; the extra \r shows up as a ^M when you view a file with windows line-endings on Unix.

Adding the following setting to your user settings should help (although I’m not sure if it will convert files already with windows line-endings):

{"default_line_ending": "unix"}

To change the line endings of an existing file, try the dos2unix command in Unix, something like:

dos2unix -o your_file.xyz

Note: I would check out the man page of dos2unix before you execute this command (since it can overwrite your file).

1 Like

#3

I have setup the default_line_ending to unix in the default settings but nothing change after restarting sublime. It’s adds the ^M in new lines…

Thanks for the response

0 Likes

#4

I guess the setting will only work for new files. I guess you will have to convert the line-endings in the file (cygwin should also include the dos2unix utility) before SublimeText will treat it that way. If a file has windows line-endings then SublimeText will respect those line-endings, regardless of what the default_line_ending setting is (which makes sense).

0 Likes

#5

There is an easier way to change your line endings, go into the View menu and select Line Endings. Now all line ends will be in the desired format.

Cheers,
Chris.

1 Like

#6

Cool. I never saw that before. Very useful. Thanks!

1 Like