how to make vim show ^M and substitute it
Display CRLF as ^M:
:e ++ff=unix
Substitute CRLF for LF:
:setlocal ff=unix
:w
:e
Vim does show ^M except in one case: if the fileformat=dos then it will not show a trailing crlf.
You can find out which format (unix or dos) you have by typing :set
and you can get rid of the ^M in the crlf by just changing the format (:set fileformat=unix
) and then writing out the file.
If you have a ^M in the middle of the line, then you should be able to see it, even in a fileformat=dos
file, and you can pattern match it with \r
. (Oddly, the syntax for subsituting a newline is a \r
in the replacement part of the sub, so the way one changes ^M to ^N is by the not-at-all-a-noop :s/\r/\r/
.)
vim is autodetecting the fileformat and switching modes to match (take a look at set ff
)
If you want to force it to open in a particular mode, toss a +ff=unix
(to show the ^M) or +ff=dos
in your command line to open it in that mode. If you're on a windows box, just try :e ++ff=unix
after opening the file.
If you're trying to just strip those characters out, you can open it in one mode, set the ff to what you want, and then save the file. Check out :h ff
for more details.