Endlines not consistent between text editors

Started by
6 comments, last by Will F 18 years, 8 months ago
Hi, This really gets to me... Sometimes I open a text file in one text editor and all the text appears on one line without any endlines. Or sometimes I open it and there's an extra blank line between every actual line of code. This might have to do with the fact that the piece of code I'm trying to edit was written by someone who uses Linux and I use windows (VC++). So, other than forcing to make everyone use the same text editor, is there any way to solve this problem? Perhaps visual studio has some option hidden away somewhere to correctly read endlines in files that were created in Linux? Thanks roos
Advertisement
Sounds like you have some newline transition problems. Personally I've never had problems with MSVC opening the files properly. However, sometimes you can get around the problem with using Wordpad to open and then save the file.

How are you sharing the source? One way to avoid this kind of thing is to use FTP in A mode to transfer files since it should adjust the newline conventions to be the same as the clients.
Thanks for replying SiCrane... Yeah, I thought about just opening the file up in WordPad and then re-saving it. Though that would fix the problem for me, are you sure that wouldn't cause the endlines to be messed up for the other coders when they open it in vi or emacs or whatever? Right now I'm the only guy on the team using Windows so I'd hate to screw everything up for the rest of the dev team as the first thing I do after they accepted me to their team, lol.

As for sharing the source, we're using CVS provided by SourceForge. I just did a checkout using TortoiseCVS.

Thanks,
roos
Quote:
This really gets to me... Sometimes I open a text file in one text editor and all the text appears on one line without any endlines. Or sometimes I open it and there's an extra blank line between every actual line of code.


This happens because of a difference in the way in which linux and windows represent newlines. On linux, \n (line feed) is sufficient to indicate a newline whereas on windows \r\n is used (carriage return followed by line feed). I believe dos/windows uses \r\n because of the way early printers worked. Pre OS X used \r (carriage return) as the newline.

In your case, a single line file would indicate that the file was written with a *nix text editor and therefore contains \n instead of \r\n. May I suggest that it also indicates that the text editor is somewhat primitive(notepad perhaps?). Any half-decent windows text editor will interpret \n or \r properly. The double spacing probably happens because the text editor believes the text file was created in *nix and therefore interprets \r\n as two new lines.

To complicate matters further, network standards use \r\n as a newline. This can sometimes cause problems for *nix users who don't realise it.


Unfortunately, I can't help with your VC++ query. I imagine it will have such a an option though.

Quote:
... are you sure that wouldn't cause the endlines to be messed up for the other coders when they open it in vi or emacs or whateve

In my experiance Vim under linux will correctly recognise a windows text file and interpret the \r\n as a single space. Like SiCrane mentioned, I often use ftp or ssh to transfer files between linux and windows so \n may get converted to \r\n automatically.
Don't know about Visual Studio, but most Java IDEs will have an option to set the newline convention to any of the three options.

shmoove
In case you can't get it to work, there's a couple of programs to convert with. Google for dos2unix and unix2dos.
You don't even need to open the file in Wordpad - just copy-paste it in, then copy-paste it back out again into the original editor. As a result, I can now type Ctrl+A Ctrl+C Win+R write Enter Ctrl+V Ctrl+A Ctrl+C Alt+F4 N Ctrl+V very fast. [wink]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Obligatory link to wikipedia article on NewLine. [wink]

This topic is closed to new replies.

Advertisement