16

In Windows, Emacs is using cr-lf for a linebreak, but I like all my files to use Unix line endings (lf). I found a way to change it during my session, but I am not such an Emacs guru to translate the solution into an elisp command in my .emacs file.

Can anybody help me, so Emacs in Windows will use lf permanently?

Brian Burns
  • 20,575
  • 8
  • 83
  • 77
Sambatyon
  • 3,316
  • 10
  • 48
  • 65
  • 1
    possible duplicate of [How to configure GNU Emacs to write UNIX or DOS formatted files by default?](http://stackoverflow.com/questions/1674481/how-to-configure-gnu-emacs-to-write-unix-or-dos-formatted-files-by-default) – phils Mar 18 '12 at 20:00
  • I guess I didn't look for the right keywords before asking. So, now we close it, or do I delete this question, or what is the procedure? – Sambatyon Mar 19 '12 at 06:43
  • Normal procedure is automatic closure once a handful of people have confirmed it as a duplicate. I'm not sure if you can delete the question once there are answers? In any case, duplicates can often act as useful redirection if the original question is harder to find. – phils Mar 19 '12 at 06:49
  • FWIW, this is the first hit on Google for 'emacs default line endings' - no other StackExchange answer shows on the first page. – Brian Burns Feb 19 '15 at 18:10

1 Answers1

24

As per the comment by Brian Burns, use this for modern Emacs.

(setq-default buffer-file-coding-system 'utf-8-unix)

Prior to Emacs 23.2, you would use

(setq default-buffer-file-coding-system 'utf-8-unix)

See also How to configure GNU Emacs to write UNIX or DOS formatted files by default?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 13
    According to the docs, this variable is obsolete since 23.2 - use `(setq-default buffer-file-coding-system 'utf-8-unix)` instead. And use setq-default with this variable because it automatically becomes buffer-local when set, but you can set the global value with setq-default. – Brian Burns Feb 19 '15 at 18:31
  • 2
    If you want to keep the behavior of using DOS line endings if you open a file that uses them, but you need to change it for a single buffer, `(setq coding-system-for-write 'utf-8-unix)` will do the job. Invoke with `M-x eval-expression` – trey-jones Apr 07 '22 at 13:20