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.

2 Answers 2


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.

  • I would suggest a better solutino than dos2unix since it would fix occurences everywhere: perl -pi -e 's/\r//g ;' file.txt.
    – dan
    Jan 5, 2017 at 21:36
  • Sorry I forgot this question completely. Actually, I don't mind open Vim and batch-replace by :bufdo %s/\r/\r/g. Your suggestions are all reasonable. Jan 27, 2017 at 13:09

When I understand you right, the problem lies in the OSX Clipboard. It's the place to fix the behaviour, if there is one. See e.g. https://stackoverflow.com/questions/3482289/easiest-way-to-strip-newline-character-from-input-string-in-pasteboard on how to deal with newlines in the OSX Clipboard.

You must log in to answer this question.

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