Somebody in my team has checked in a file with MS-DOS line endings into the git repo. with vi's binary mode, vi -b hello.py, i can see lines ending with ctrl character - ^M.

In emacs, whitespace-mode, the same characters are shown with $ sign. I infer, emacs has changed ^M/$ chars uniformly to $ chars.

How can i restrict emacs from converting windows line feed into unix line feed and rather show the line feed chars - ^M in its original form and not as $?

I am trying to figure out, if git local repo can be configured to do this windows to unix line feed mapping, rather than emacs doing it.

  • 1
    Note that Emacs does not automatically convert from one EOL type to another. It will just recognise the EOL style for a given file (if it is consistent) and display the file as if that style was native.
    – phils
    Jul 26, 2015 at 20:37
  • 2
    What do you see in mode line? It should show current encoding, so if you're on Unix-like system, it will show DOS label. Do you see it? You can easily convert entire file into Unix EOL style with C-x RET f or M-x set-buffer-file-coding-system. Git can be scripted to perform such conversion automatically too, but this requires additional efforts. See here for example. Jul 27, 2015 at 17:32

1 Answer 1


First, ^M is the carriage-return character, not the linefeed char (that one is ^J.

Here is one answer for this part of your question: How to show the line feed chars - ^M in its original form and not as $:

  1. By default, ^M characters should be highlighted using face escape-glyph. Are you sure this is what you are seeing? Try customizing that face (M-x customize-face) to something more noticeable than the default coloring.

    If you do not see escape-glyph highlighting with your Emacs setup, try starting from emacs -Q (no init file). Now do you see this highlighting?

    If so, then recursively bisect your init file, to see which part of it introduces the problem. You can use command comment-region to comment out a selection of text, and C-u with that command to uncomment a selection.

  2. You can also try using library highlight-chars.el, which gives you more options for highlighting characters (any characters). Here is more info about this library.

For the line-end conversion part of your question, have a look at the Emacs manual, node Text and Binary.

Someone else can speak to how you might use GIT to perform the conversion automatically.

  • Drew, i installed highlight-chars.el. when i run hc-highlight-chars, the minibuffer prompts Chars to highlight. How can i give the control character ^M` here. Since C-v \n that i use in vim, has got other bindings it seems
    – Saravana
    Jul 27, 2015 at 0:39
  • 2
    You can always insert a control character in Emacs using C-q. So you hit C-q RET (or C-q C-m). See the Emacs manual, node Inserting Text. The key RET (or C-m) is itself bound to a command, so it is not self-inserting in the minibuffer (or in most other contexts, for that matter).
    – Drew
    Jul 27, 2015 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.