39

Most documents I'm opening in notepad.exe under windows 7 lately, there are no linebreaks... everything just runs together. The same documents in any other program, even previewed directly in Explorer, will show the linebreaks correctly. this is happening with many .info files, .css, .js.. but not all of them.

I am guessing it's some kind of character encoding unix line endings something or other, but wondering if there's anything I can do or if anyone else has experienced similar and if I can make notepad work correctly. I prefer it to notepad++/other text editors for certain uses.

Stevoisiak
  • 16,075
Damon
  • 2,789
  • 6
  • 28
  • 29

7 Answers7

46

There are line-breaks, however different operating systems recognise different sequences for line-breaks.

Notepad only recognises CR, LF (0x0d, 0x0a), whereas other sources might use CR only, or LF only.

You can't make Notepad behave differently, so your only option is to make sure the content has the right sequence for Notepad. Note that notepad is the only editor with this restriction, so if your content works in Notepad, it will work everywhere else.

One simple way to fix the line-feeds is to copy and paste the text into Word, then back again into notepad, and the line-feeds will get "corrected" to the CR,LF sequence.

Paul
  • 61,193
9

Wordpad

If your aversion to notepad++ and other text editors is that they are not a standard part of all Windows systems, use Wordpad. It's not quite as rudimentary as Notepad.

Wordpad will correctly read and display text files with with Unix line-endings.

Other

If you are averse to both the one-true text editors then notepad++ is probably a good choice.

5

You could write a simple batch script:

@ECHO OFF
TYPE %1 | FIND /V "" >%1.1
MOVE %1.1 %1 > NUL 2>&1
START "NOTEPAD" C:\WINDOWS\SYSTEM32\NOTEPAD.EXE %1
EXIT /B

Save this as notepad.bat in whatever directory you like. Then, instead of opening your .info/.css/.js files with Notepad, open them with this batch script. It will automatically convert all Unix line endings to DOS and then open the file with Notepad.

Drawbacks:

  • Every time you open the program it appends a newline to the end of the file. (Fixed by @mpag)
  • Opens a Command Prompt window (Fixed using START on line 4)
  • Changes the file's creation date to the current date
MD XF
  • 224
5

As Notepad++ was mentioned specifically in the OP, it (at least now) has the setting needed under:

Edit --> EOL Conversion --> Windows Format.

James Mertz
  • 26,529
Huendli
  • 51
3

You need to change the type of line-break encoding used in the file.

In Linux there is a program called "unix2dos" that can do that for you. I am unsure if Windows comes with such a program, but there appears to be a similar one available here: http://www.thefreecountry.com/tofrodos/

There is more information regarding this process in Wikipedia: http://en.wikipedia.org/wiki/Unix2dos where you can get examples of different command line programs that can do the change.

rgocs
  • 191
  • 1
  • 4
1

Another thing you could do: Open the file in WordPad and then save it. It will correct the line endings. This is the fastest method.

MD XF
  • 224
1

You're correct that it's an issue with Unix line endings. There are several different line endings, but three variations are the most common:

  • "U+000A LINE FEED" (LF): Unix, Linux, macOS, etc
  • "U+000D CARRIAGE RETURN" (CR): classic macOS among others
  • "U+000D CARRIAGE RETURN" followed by "U+000A LINE FEED" (CRLF): Windows and other non-Unix/IBM operating systems

Older versions of Notepad recognise only CRLF, but newer versions support CRLF, CR, and LF.

There's no setting to change this behavior in older versions of Notepad, but you can revert to the old behavior in the new version. Most other mainstream programs have worked with all three line endings for quite some time, so if your content works in older versions of Notepad, it should work pretty much everywhere else.

0b10011
  • 111