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.

1

7 Answers 7

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.

14
  • 38
    aha! sounds a bit like ditching notepad might be far easier ;P
    – Damon
    Nov 28, 2011 at 4:02
  • 1
    Absolutely (padding).
    – Paul
    Nov 28, 2011 at 4:04
  • 4
    I think it is really baffling that this twenty year old limitation hasn't ever been fixed...
    – Haroldo_OK
    Nov 25, 2016 at 11:47
  • 1
    open with word, save, then open with notepad... no copy-paste necessary Jun 21, 2017 at 19:38
  • 2
    Good news, the technology is finally arriving.
    – mkobit
    May 9, 2018 at 19:11
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.

4
  • 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
    Nov 29, 2011 at 16:44
  • 2
    For anyone reading this years later, You can turn this functionality off in the preferences, its something like "Remember current session for next launch"
    – Uberfuzzy
    Aug 19, 2014 at 20:26
  • 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
    Mar 12, 2015 at 15:29
  • 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
    Oct 25, 2018 at 12:15
5

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

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

1
  • Notepad++ 7.5.9 version, options has name "Windows (CR LF)" under EOL Conversion. Dec 17, 2018 at 13:53
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
6
  • Let us continue this discussion in chat.
    – mpag
    May 10, 2017 at 20:54
  • 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
    May 10, 2017 at 22:44
  • @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
    May 10, 2017 at 23:57
  • 1
    to 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
    May 11, 2017 at 0:50
  • Or you could just use this pre-existing utility.
    – mbomb007
    Oct 2, 2018 at 13:56
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.

1
  • 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. Apr 30, 2014 at 17:12
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.

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.

Not the answer you're looking for? Browse other questions tagged .