Home Download Buy Blog Forum Support

Sublime adds control-m in lines

Sublime adds control-m in lines

Postby davidsf on Thu Mar 15, 2012 8:55 am

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
davidsf
 
Posts: 2
Joined: Thu Mar 15, 2012 8:51 am

Re: Sublime adds control-m in lines

Postby jbjornson on Thu Mar 15, 2012 9:46 am

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):
Code: Select all
{"default_line_ending": "unix"}


To change the line endings of an existing file, try the dos2unix command in Unix, something like:
Code: Select all
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).
jbjornson
 
Posts: 348
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Sublime adds control-m in lines

Postby davidsf on Thu Mar 15, 2012 11:37 am

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
davidsf
 
Posts: 2
Joined: Thu Mar 15, 2012 8:51 am

Re: Sublime adds control-m in lines

Postby jbjornson on Thu Mar 15, 2012 11:56 am

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).
jbjornson
 
Posts: 348
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Sublime adds control-m in lines

Postby CLarge on Fri Mar 16, 2012 7:20 am

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.
CLarge
 
Posts: 1
Joined: Fri Mar 16, 2012 7:17 am

Re: Sublime adds control-m in lines

Postby jbjornson on Fri Mar 16, 2012 1:08 pm

CLarge wrote: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.


Cool. I never saw that before. Very useful. Thanks!
jbjornson
 
Posts: 348
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests