next up previous contents
Next: Multiple Windows, Buffers, and Up: Formatting Your Text Previous: Changing Case   Contents

End of Line Characters

If you frequently deal with text files created by Windows users, you will no doubt encounter the frustrating $\backslash$M character littered throughout the text. Remember that Unix, Windows, and Macs prior to OS X all deal with the end of lines differently. Windows marks the end of a line with two characters - an end of line ($\backslash$ n) and a carriage return ($\backslash$ r). Unix just uses the end of line ($\backslash$ n), and Macintosh just uses the carriage return ($\backslash$ r). When you open a text file originally created in Windows, the $\backslash$M characters represent left-over carriage returns emacs didn't know what to do with.

There is an easy way to get rid of them by just searching and replacing. Navigate to one of them, select it the way you would any other character or expression, and copy it using M-w. Then Hit M-% to begin a search and replace session. When emacs asks what to replace, hit C-y (yank). When emacs asks with what to replace the character, just hit return. Emacs will then remove all those $\backslash$M characters. You can also type C-q (``enter a literal'') followed by C-m to enter the end-of-line character directly, when asked.


next up previous contents
Next: Multiple Windows, Buffers, and Up: Formatting Your Text Previous: Changing Case   Contents
Randall Wood 2011-03-31