victor NOAGBODJI wrote:
Hello,
I usually write on both win and linux.
Whenever I open win edited files in linux, I've got ^M at end of each line.
Is there anything to automatically change that?
^M (control-M) is the carriage-return (CR) control character. Typically,
lines of ASCII text are ended by only LF (line feed, ^J, control-J) on
Unix, by CR and LF on Windows (and by CR only on Mac).
- To automagically recognise files with Dos-like ends-of-lines:
:set fileformats+=dos
(Note: the 'nocompatible' default already includes "dos".)
- To convert a particular file from CRLF to LF only:
:e ++ff=dos foobar.txt
:w ++ff=unix
(Note: if a file has become corrupt, with some Dos endings and some Unix
ones, the above ought to correct it, because when reading a file in Dos
fileformat mode, Vim regards either CR followed by LF or LF alone as an
end-of-line.)
- To convert from LF to CRLF, the procedure is obviously the reciprocal:
:e ++ff=unix foobarbaz
:w ++ff=dos
see
:help 'fileformats'
:help ++opt
Best regards,
Tony.