Windows – Notepad++ new line only inserting CR when opening empty file (0 byte text file created in Windows Explorer)

notepadwindows 7

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?

Best Answer

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.

Related Question