To deal with superfluous carriage returns in TextEdit

formattingms officetext-editortextedit

I want to let TextEdit never save <CR>, the carriage return.

Different operating systems save end-of-line as different Unicode characters.
For MS DOS (like Windows) it is <CR><LF>, and for Unix and Mac <LF>, and for the very old Mac OS 9 just <CR>.
Here <CR> is the carriage return, and <LF> the line feed.

When sometimes I paste, into TextEdit, several paragraphs from a Windows-created file, for example pdf or doc/docx, <CR>'s are also copied.
TextEdit does not fully conform with Unix standards, in that it does accept <CR><LF>'s, by showing them indeed as line breaks.
I cannot tell, then, whether a line break is Window-styled <CR><LF> or Unix-styled <LF>.

When I save my personal writings in pure text (txt) written in Markdown, I don't want these <CR>'s, but can neither see them, nor delete them in TextEdit.
It is when I open the text file in question with Vim, did I spot those <CR>'s shown as ^M.
Indeed, in Vim, it is easy to replace them with empty strings.

However, I too edit in TextEdit often.
Can I set TextEdit so that it never saves <CR>'s in a buffer of its?
That is, when I paste a <CR> in a buffer, the <CR> is ignored and not written.

Best Answer

I don't believe that TextEdit has such an option. It happily accepts all line ending types (even intermixed within the same file) and displays them properly.

You would probably need to use a text editor where you have direct control over the line endings and text encoding type when saving the file. BBEdit is a great text editor that has such controls.

Another option is to convert the file with a utility like dos2unix. The website doesn't offer a macOS binary download so you would need to either compile it yourself or install a package manager like Homebrew first then install the dos2unix package with brew install dos2unix. For an easy solution you can just run perl -pi -e 's/\r\n/\n/;' FILE.TXT as well.