Notepad ignoring linebreaks
Solution 1
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.
Solution 2
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.
Solution 3
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 usingSTART
on line 4) - Changes the file's creation date to the current date
Solution 4
As Notepad++ was mentioned specifically in the OP, it (at least now) has the setting needed under:
Edit --> EOL Conversion --> Windows Format.
Solution 5
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.
Related videos on Youtube
Damon
Updated on September 18, 2022Comments
-
Damon almost 2 years
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.
-
VonC almost 6 yearsSee stackoverflow.com/a/50241693/6309: Notepad does support \n now (Windows 10, Q2 2018)
-
-
Damon over 12 yearsaha! sounds a bit like ditching notepad might be far easier ;P
-
Paul over 12 yearsAbsolutely (padding).
-
Damon over 12 yearsmy 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. -
Arkana almost 11 yearsI 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 :)
-
Junior Mayhé about 10 yearsif 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. -
Haroldo_OK over 7 yearsI think it is really baffling that this twenty year old limitation hasn't ever been fixed...
-
bambams over 7 yearsThank 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!
-
Davut Gürbüz over 7 yearsThat 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. -
Kyle Delaney over 7 yearsThe 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.
-
Ken Bellows over 7 years@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 -
Davut Gürbüz over 7 years@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.
-
mpag about 7 yearsLet us continue this discussion in chat.
-
mpag about 7 yearsanother recommendation. replace the
start
line withSTART "NOTEPAD" "%SystemRoot%\System32\NOTEPAD.EXE" %1
to generalize for those crazies that have D as their root drive or WinNT for their windows directory. -
MD XF about 7 years@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. -
mpag about 7 yearsto 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
-
Gavin Palmer about 7 yearsopen with word, save, then open with notepad... no copy-paste necessary
-
Syed Waqas Bukhary over 6 yearsI think you need to bold from "One simple Way..." so that people don't have to read CR and LF and all that stuff.
-
Paul over 6 years@WaqasBukhary You are always welcome to edit answers to enhance them
-
Syed Waqas Bukhary over 6 yearsI can edit, but don't have the rights to edit less then 6 chars.
-
mkobit about 6 yearsGood news, the technology is finally arriving.
-
mbomb007 over 5 yearsOr you could just use this pre-existing utility.
-
patrik over 5 yearsWould 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.
-
André M. Faria over 5 yearsNotepad++ 7.5.9 version, options has name "Windows (CR LF)" under EOL Conversion.
-
12431234123412341234123 almost 3 yearsYou could also use unix2dos when it is available.