Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Background: I ran into a really odd issue where part of a php page just stopped parsing but only when it was uploaded to the server. Runs fine locally. The part where it cut off was after a commented line of code. Removed the comment it parsed up till the next comment.

Turns out the issue was line endings. They were CR only without a LF, and the server being *nix doesn't recognize CR alone as a new line, thus it interpreted the comment as extending to the entire rest of the file.

I tried creating a new file (after turning on "show all characters") inside Notepad++ and pressed enter. It showed CRLF.

Next I created a new text file in Windows explorer (Win7 x64) then opened it in Notepad++. I pressed enter and it only inserted CR not LF.

Now the actual question is why? As far as I know Windows should be based on CRLF not just CR. Also is there a way to have Notepad++ always use CRLF, or at least assume CRLF with a 0 byte file?

share|improve this question
add comment

3 Answers

I don't know why part of your file is in Windows format and part of it is in Mac format, but it should be as easy as selecting Edit->EOL Conversion->Windows Format, and the entire file should be converted to CRLF. Notepad++ uses the format that is used in the file that is opened. AFAIK, there is no way to force it. One option might be to show the line ending characters (View->Show Symbol->Show End of Line) so you know what you're dealing with when you open a file.

share|improve this answer
    
Thanks, Edit->EOL Conversion->Windows Format is what I couldn't find. Ended up doing a find/replace with extended chars but this is much more reliable. –  Davy8 Dec 10 '10 at 14:01
    
But "part of your file is in Windows format and part of it is in Mac format" is not what I said. Basically if I open a 0 byte file it should be in no format because there's no data to base anything off of. The question is that in this case why does it assume the "Mac format"? –  Davy8 Dec 10 '10 at 14:04
    
Sorry, I must have misread that. I thought that it started out in Windows format and that it changed to Mac format somewhere before the first comment. Will edit answer to fix. –  MBraedley Dec 10 '10 at 19:36
    
Also, I was wrong earlier (it was first thing in the morning for me). In the preferences, under the New Document/Default Directory tab, you can set the line ending format for new files. –  MBraedley Dec 10 '10 at 19:41
add comment
up vote 3 down vote accepted

When opening a zero-length file, it uses the line-ending of the most recently opened file. That's why I was getting varied results.

share|improve this answer
add comment

You can set the default EOL format for new files in the "New Document/Default Directory" preferences tab. I believe the default is Windows, but if it's set to Mac format that may be why it used CR for the 0 byte file.

share|improve this answer
    
Actually it is set to Windows. If I create a new document inside Notepad++ it works as expected. The problem only arises from opening an already existing 0 byte file. –  Davy8 Dec 10 '10 at 21:06
1  
When you first open a 0 byte file, does the status bar say "Dos\Windows" or does it say "Macintosh"? –  Velociraptors Dec 10 '10 at 21:37
    
it says Mac... actually yesterday it said Mac... today it says Unix. Creating a new document inside Notepad++ says Dos\Windows... no idea wtf's going on. –  Davy8 Dec 11 '10 at 2:00
    
Either Windows is doing something weird or there's a bug in notepad++. As a work-around, you could either create the files in notepad++ or set a keyboard shortcut for the Windows format EOL conversion so it's faster to make sure you always have CRFL. –  Velociraptors Dec 11 '10 at 23:37
    
I've had the same thing happen to me in Notepad++ and it's been driving me up the wall suspecting a bug in Notepad++. Turns out I now suspect that I am inadvertently hitting either Ctrl+M (Mac EOL 0xD only) or Ctrl+J (Unix EOL 0xA only) as I'm typing. These seem to be default keyboard shortcuts for Notepad++ -- annoying! Currently trying to find out how / where to disable these (they're not in the usual Settings > Shortcuts menu. –  Assad Ebrahim Sep 27 '12 at 0:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.