As far as CR vs CRLF and Windows vs Unix go, Vim tries to keep things pretty and not expose expected control characters.
In other words, Vim, by default (see below), guesses what type of file ("dos" or "unix") is being edited based on the line endings. (I'm ignoring "mac" here for the sake of simplicity.) It's guess is stored in 'fileformat'
(alias 'ff'
).
In your case, with CRLF line endings on Windows, you can expect 'ff'
to be set to "dos". So the carriage return (^M
) is expected and not shown.
In Vi you'd be more likely to see ^M
...
If you use the good old Vi and try to edit an MS-DOS format file, you
will find that each line ends with a ^M character. (^M is <CR>). The
automatic detection avoids this.
If you really want to see the ^M
, though, you can overrule the format with this:
:edit ++ff=unix file.txt
++
does per-command overriding of default values of a setting. ++ff
is used for 'fileformat'
. You could also use ++ff=dos
for the reverse scenario. (Note: the only settings supported by ++
for override currently are 'fileformat'
and 'encoding'
.)
This is all from :h usr_23.txt
under the section named "Overruling the Format".
Update: Right around the time I was submitting this I noticed your edit where you mention you tried :set ff=unix
. That won't work on its own. There is another setting 'fileformats'
(alias 'ffs'
) that influences the behavior. On Windows the default is "dos,unix". Multiple values in 'ffs'
turn on auto-detection which overrides your manual setting of 'ff'
.
If you unset 'ffs'
with :set ffs=
, though, that will disable auto-detection and :set ff=unix
should work then.
When 'ffs'
is empty then the format defined with 'fileformat'
will be used always.
(From :h 'ffs'
)
(Why does ++ff=unix
work without requiring you to change 'ffs'
? Because that's how it's implemented. ;)