Notepad ignoring linebreaks

36

6

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.

Damon

Posted 2011-11-28T03:30:41.487

Reputation: 2 119

Question was closed 2019-04-11T10:17:33.673

See https://stackoverflow.com/a/50241693/6309: Notepad does support \n now (Windows 10, Q2 2018)

– VonC – 2018-09-26T06:25:43.217

Answers

45

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

Posted 2011-11-28T03:30:41.487

Reputation: 52 173

3I think it is really baffling that this twenty year old limitation hasn't ever been fixed... – Haroldo_OK – 2016-11-25T11:47:36.770

Thank you for the Wordpad back to Notepad hint! That's a very handy, and easy trick that will work in a pure Windows install without having to remember or install any custom code! – bambams – 2017-01-19T15:40:56.657

That is interesting if your text only contains LF char and you paste it to WordPad,NotePad++ kind of tools on windows these apps automatically correct as you said add CR before each LF. I use some hex tools to see actual data this is an online onehttps://hexed.it/. Even @RichTextBox in Microsoft's SDK ends lines with LF only. But @TextBox works like notepad by default for Windows Forms Applications. Why is it designed so I have no idea but this is how I reached to this SO question. – Davut Gürbüz – 2017-01-31T07:54:38.703

The copying and pasting back to Notepad trick doesn't work with read-only text files. It's only useful if you can save it. Ditching Notepad seems best. – Kyle Delaney – 2017-03-15T18:01:33.420

@DavutGürbüz WordPad might correct it and add the CR (\r), but in my experience Notepad++ and most other editors do not automatically add CRs, they just know how to display LFs properly; if I paste some LF-only code, for example, into Notepad++, then copy it from there and paste it into regular Notepad, it still shows on a single line because it's still missing CRs – Ken Bellows – 2017-03-27T17:11:13.977

@kenbellows my point was it's interesting apps behave different because of their underlying components. If you past [CR] only data from notepad to notepad++ you will see [LF] added. But if you open file from dialog it shows as is. – Davut Gürbüz – 2017-03-28T07:56:26.757

1open with word, save, then open with notepad... no copy-paste necessary – Gavin Palmer – 2017-06-21T19:38:55.237

I think you need to bold from "One simple Way..." so that people don't have to read CR and LF and all that stuff. – Waqas Bukhary – 2017-11-11T06:20:44.403

@WaqasBukhary You are always welcome to edit answers to enhance them – Paul – 2017-11-11T06:23:29.030

I can edit, but don't have the rights to edit less then 6 chars. – Waqas Bukhary – 2017-11-11T06:26:37.120

2

Good news, the technology is finally arriving.

– mkobit – 2018-05-09T19:11:18.523

36aha! sounds a bit like ditching notepad might be far easier ;P – Damon – 2011-11-28T04:02:46.793

1Absolutely (padding). – Paul – 2011-11-28T04:04:56.637

I copied/pasted a text from NP++ to Notepad (Win). Because it wasn't properly encoded, Notepad ignores my line-breaks. I set the encoding in NP++ to "UTF-8" and everything works fine. Thanks :) – Arkana – 2013-07-10T10:39:11.263

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.

RedGrittyBrick

Posted 2011-11-28T03:30:41.487

Reputation: 70 632

2For anyone reading this years later, You can turn this functionality off in the preferences, its something like "Remember current session for next launch" – Uberfuzzy – 2014-08-19T20:26:42.697

2@Damon I used to hate this behavior, too, but you can disable it. You just need to configure Notepad++ not to reopen old sessions. Go to Settings --> Preferences --> Backup. Uncheck "Remember current session for next launch". – Bacon Bits – 2015-03-12T15:29:10.783

Would say that the problem is not so much about wanting the text editor to be a ported with Windows, as much as wanting Windows to provide at least one decent text editor. I would not count either MS Word or WordPad as "text editors", since the purpose of these tools rather are generating reports, than editing text. Text does not come necessarily come with pages or have to fit on pages. Still in 2018 and Windows 10, I have not found any of this. – patrik – 2018-10-25T12:15:18.480

my prob w/ notepad++ for really quick viewing/editing is actually that it keeps multiple documents open unless I specifically close them; just doesn't feel right for that use. I may just reassociate text type files with worpad and make sure it's in my open with... menu. – Damon – 2011-11-29T16:44:43.943

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

Posted 2011-11-28T03:30:41.487

Reputation: 214

Let us continue this discussion in chat.

– mpag – 2017-05-10T20:54:04.603

another recommendation. replace the start line with START "NOTEPAD" "%SystemRoot%\System32\NOTEPAD.EXE" %1 to generalize for those crazies that have D as their root drive or WinNT for their windows directory. – mpag – 2017-05-10T22:44:13.273

@mpag Sure, except I don't feel the need to edit that into my answer. Anyone wacko enough that their root directory isn't C: will get no support from me. C: has been the standard since DOS came out in 1981. – MD XF – 2017-05-10T23:57:25.550

1to preserve timestamps: mkdir %1.dir TYPE %1 | FIND /V "" >%1.dir\%1 robocopy . %1.dir %1 /copy:t >NUL 2>&1 move %1.dir\%1 . > NUL 2>&1 rmdir %1.dir – mpag – 2017-05-11T00:50:14.597

Or you could just use this pre-existing utility.

– mbomb007 – 2018-10-02T13:56:43.273

4

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

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

Huendli

Posted 2011-11-28T03:30:41.487

Reputation: 41

Notepad++ 7.5.9 version, options has name "Windows (CR LF)" under EOL Conversion. – André M. Faria – 2018-12-17T13:53:11.443

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

Posted 2011-11-28T03:30:41.487

Reputation: 161

if you have Sublime installed, you can choose View->Line endings -> Windows and then save the file to overwrite it. In this case unix line endings will turn into Windows format. If you open this saved file in Notepad, it will show line endings correctly. – Junior M – 2014-04-30T17:12:39.357

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

Posted 2011-11-28T03:30:41.487

Reputation: 214

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

Posted 2011-11-28T03:30:41.487

Reputation: 111