1

I am on Windows 7 running PowerShell version 2.0.

I used the following PowerShell code (from this answer: https://stackoverflow.com/a/65148/360840) to modify my PowerShell profile:

"`nNew-Alias which get-command" | add-content $profile

As expected, it appended the line in question to my profile BUT afterwards, my Vim sessions started showing ^M characters at the end of each line. Very strange! Any clue on what caused it and how to fix it? I tried set fileformat=dos in Vim but it did nothing.

Here's my Vim version information:

vim version

(Not sure how to make the picture larger - this is not its normal size.)

Community
  • 1
  • 1
Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • 1
    The image is automatically resized by the size of the surrounding element (i.e. your post's width). Just right click it and select "view image" or similar in your browser if choice. – timss May 20 '13 at 19:38

3 Answers3

4

There are some options to solve the problem in vim-faq 14.13. I am seeing a lot of ^M symbols in my file. I tried setting the 'fileformat' option to 'dos' and then 'unix' and then 'mac'. None of these helped. How can I hide these symbols?

It is possible that your file was in unix file format (all lines ending in <CR>), and you appended lines with dos file format (lines ending in <CR><NL>, what makes Vim confused.

dash-tom-bang
  • 17,383
  • 5
  • 46
  • 62
mMontu
  • 8,983
  • 4
  • 38
  • 53
1

So, I ran into this issue, and the solution was slightly different. I've checked my file format, and it's unix, you can check yours with :set fileformat? And it displays all of the ^M characters I don't want... The interesting thing, is that in the VIM manual as pointed to above at: http://vimhelp.appspot.com/vim_faq.txt.html#faq-14.13 states that the ^M line ending is from the DOS file format and that "If the file has some lines ending with and some lines ending with followed by a , then the fileformat is set to 'unix'."

So, given this it would seem that you would want to remove all of the ^M endings, and keep the endings, but removing the endings with :%s/\r$// immediately resolved the issue for me, and the file format still says 'unix'.

That's what worked for me. As a side-note, in order to provide a more google-able reference, I would like to note that I ran into this while using LocomotiveCMS. I was pulling my CSS file back down to work on locally, using Wagon. When I got it back it was full of ^M characters, the file still works fine, it's just ugly.

counterbeing
  • 2,721
  • 2
  • 27
  • 47
0

The problem was that the file became corrupted. In such a case, Vim starts displaying ^M characters to alert you to the problem. The fix was to manually remove these characters (%s/^M//g).

Still not clear to me, because these characters are SUPPOSED TO BE in the file as Windows file format uses them. But at least the problem was solved.

EDIT: Please see the exchange of comments w/ dash-tom-bang, which provides clarification.

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • 1
    Vim shows you the ^M characters not to "alert" you to anything other than the fact that the file is (probably) in 'unix' mode but *some* lines end with the DOS line ending. The easy fix is to remove all of the ^M characters then change the fileformat. (I've found it unfortunate that you can't just fix it by changing fileformat to dos but so it goes.) – dash-tom-bang May 21 '13 at 20:14
  • @dash-tom-bang: BUT the file is *on* Windows (i.e. DOS). I concur w/ you that removing ^M characters fixes the problem, but those characters are actually *needed* on DOS. That's why I say it's still not clear. +1 – Sabuncu May 21 '13 at 22:02
  • 1
    You need to remove the ^M characters so that when you switch the fileformat to dos that they aren't doubled. Once you reset fileformat you'll have the the correct CRLF line endings. – dash-tom-bang May 21 '13 at 22:12
  • @dash-tom-bang: I see, setting fileformat to DOS inserts those characters. Thanks. +1 – Sabuncu May 21 '13 at 22:23
  • I would like to add that the above command `%s/^M//g` for removal does not work for me. I've got one on all of my line endings, but when I run that it says that there are no instances to replace... Really they're just distracting, I don't care if they're removed, I just don't want to look at them! I wonder if there's a config line to just hide them. – counterbeing Oct 24 '13 at 17:11