Thanks for the help.
My gvim version is 7.0. The files are edited by Matlab editor. gvim
cannot automatically handle the ^M. No matter what file format I set.
The only thing to do is repleace them with
%s/\r/\r/g.
Frank
On 2/14/07, A.J.Mechelynck <[EMAIL PROTECTED]> wrote:
frank wang wrote:
> Hi,
>
> I have a lot of text files created in PC. When I open them in Linux
> using gvim, I get a lot of ^M and no line breaking. It is messy. How
> can I read the file correctly in Linux?
>
> Thanks
>
> Frank
>
:set fileformats=dos,unix
or
:set fileformats=dos,unix,mac
If a file has mixed ends-of-lines (CR+LF mixed with LF only) you may have to do
:e ++ff=dos filename
and, if that isn't enough
:1,$s/\r$//
which means
:1 from first line
,$ to last line
s/ substitute
\r$ a ^M at end-of-line
// by nothing
However, ^M (CR) *alone* and _no_ linefeeds is typical of Mac rather than PC.
If 'fileformats' includes "mac" Vim should still recognise them correctly. If
it doesn't, you may try
:e ++ff=mac filename
and if that _still_ doesn't work, you may break the line at every ^M by using
:1,$s/\r/\r/g
(yes, replace carriage-returns by themselves, because \r in the "replace
what?" pattern matches a ^M but in the "replace by" string it breaks the line).
Once the file has been correctly read (and possibly modified), if you want to
save it in Unix format, use
:setlocal ff=unix
:w
(to continue editing the file) or
:wq ++ff=unix
(to write the file and close the window).
see
:help 'fileformats'
:help 'fileformat'
:help ++opt
:help :s
Best regards,
Tony.
--
No man is an island, but some of us are long peninsulas.