Vi on Linux: show ^M line endings for DOS-format files

10

1

On Solaris, if you open a file in vi that has Windows line endings, this shows up as ^M at the end of every line.

On Linux, vi is cleverer and understands the Windows file format, and does not display ^M.

Is there a setting to make Linux vi behave the same as Solaris in this respect?

A common problem for us is copying a shell script off a (Windows) dev box and forgetting to dos2unix it, and then being confused when it doesn't work properly. On Solaris the problem is obvious as soon as you vi the file, but not on Linux.

Thanks.

sss

Posted 2011-11-15T18:37:12.470

Reputation: 123

On my vim, by default I usually see no ^M, but sometimes there is one at the end of the file. – trysis – 2017-03-23T19:06:37.577

On Linux, vi is usually Bram Moolenaar's vim, I expect the vi on Solaris is the Bill Joy vi, original, authentic but less capable.

– RedGrittyBrick – 2011-11-16T10:04:17.040

Answers

10

Try :set ffs=unix when starting vi (or set as default in vimrc) which should display all CR characters as ^M.

vi auto-guesses which format to use based on whether or not it encounters lines ending in just LF or both CR/LF.

Garrett

Posted 2011-11-15T18:37:12.470

Reputation: 4 039

Thus corrupts the carefully prepared user configuration. I most likely want the ffs exactly the way it is. But see the answer from @wisbucky. – fork0 – 2018-09-13T13:20:31.057

2@RedGrittyBrick - On my system, :set list shows $ at the end of all lines (Unix & DOS format), so doesn't help distinguish between the two. – sss – 2011-11-16T09:36:56.033

@sss: My mistake, I'll delete the comment. – RedGrittyBrick – 2011-11-16T10:00:56.767

2@gman - this command didn't work for me precisely - I got Not an editor command: ffs=unix - but set me on the right path. Running :set ffs=unix with the file open in vi didn't work - no error but nothing happened. I put set ffs=unix in my .vimrc file and that worked. – sss – 2011-11-16T10:09:16.300

I experienced exactly the same thing as @sss – SSH This – 2013-05-02T21:58:16.573

2

To show dos line endings for the current file:

:e +ff=unix

This forces the fileformat to unix, which will render CR as ^M


To make this setting permanent, add to ~/.vimrc:

set ffs=unix

Note that the .vimrc setting is ffs, not ff.

wisbucky

Posted 2011-11-15T18:37:12.470

Reputation: 1 522

This should be :e ++ff=unix, I believe. – fork0 – 2018-09-13T13:21:40.067

0

:e ++ff=unix

(per fork0) 54321

Jan Kyu Peblik

Posted 2011-11-15T18:37:12.470

Reputation: 188