Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In emacs, how to strip CR (^M) and leave LF (^J) characters?

No need to find replace. Just use.

M-x delete-trailing-whitespace

You can also set the file encoding through

C-x RET f unix

Oops. That ^J^M needs to be entered as two literal characters. Use c-q c-j, c-q c-m and for the replacement string, use c-q c-j.


No need for hexl-mode for this. Just do a global-search-and-replace of ^J^M with ^J Works for me. :) Then save the file, kill the buffer, and revisit the file so the window shows the new file mode (Unix vs DOS).


There's also a command-line tool called unix2dos/dos2unix that exists specifically to convert line endings.