[Techtalk] get rid of "^M" in a file

Akkana Peck akkana at shallowsky.com
Sat Jun 18 06:41:17 EST 2005


Gebhard Dettmar writes:
> was: if I don't see them I don't bother about them (should I make this a 
> new thread?) The pitfall is then, and that's why I asked if the OP sees 
> them in vim - he has troubles with vim, checks his vimrc, sees no ^M --> 
> thinks "there's nothing wrong in here". But obviously he does see them - 
> either he has a setting like 'set ff=I_don't_know' or he used less -u

Vim automatically converts line endings, at least on all the linux
systems I've used recently. It adds "[Converted]" or "[dos]" or
"[mac]" somewhere in the status line at the bottom of the screen,
but it's easy to miss that.

Vi, and I think older vim versions, didn't convert by default (if
they were even capable of it); they showed a "^M" at the end of each
line.

I wonder, is there a setting in vim which would make it behave that
way, showing the errant carriage returns rather than converting them?
I've often wanted that, for much the same reason Gebhard does.
I get a file from someone, I vim it to make a minor change, then
it totally fails when I try to use it in some program that's less
tolerant of line endings (e.g. a Makefile). If I could get vim to
warn me about this like vi always used to, I'd be saved that confusion.

I found some info in the Vim FAQ:
http://vimdoc.sourceforge.net/vimfaq.html#14.13
which didn't answer the question, but in the last of the long list
of similar help topics they suggest, I found that typing :help 23.1
mentions the issue and offers the following suggestion:

:edit ++ff=unix file.txt

This doesn't seem to work from the cmdline (i.e. you can't say
vim ++ff=unix file.txt and have it work), it doesn't work in .vimrc,
and there doesn't seem to be any way to change to this mode for an
existing file.  As far as I've been able to determine, the only time
you can do this is by starting vim then typing that command
explicitly to open the file from an already-running vim. Not very
useful! 

Maybe some of the vim experts here can read :help 23.1 and
tell me if I'm missing something there.

	...Akkana


More information about the Techtalk mailing list