On 22/04/09 11:31, Kiffin Gish wrote:
>
> What's the quickest way to remove all the trailing ^M characters in my
> file?
>
> -
> Kiffin Gish<[email protected]>
> Gouda, The Netherlands

IMHO, in Vim 7.2.040 and later, by opening it with

        :e ++ff=dos somestuff.txt

This will force Vim to read it as if it were a DOS file, which in turn 
means that CR (carriage return, or ^M) characters will be ignored 
whenever they are immediately followed by a LF (linefeed), and that LF 
will be accepted as an end-of-line marker regardless of whether it is 
preceded by a CR.

Then if you want to write it with LF-only ("Unix-style") ends of lines, 
so that no Unix program "sees" the carriage returns, use

        :setlocal ff=unix

once the file is open, and before saving it; otherwise Vim will write 
the file with CR+LF ("DOS-style") ends of lines throughout, and the next 
time it reads the file, it will regard it as a "dos" file and you won't 
see the ^M characters.

(Before 7.2.040, files with mixed CR+LF and LF-only ends-of-lines would 
be opened as fileformat "unix" even if you used the ++ff=dos modifier, 
unless 'fileformats' (plural) was set to empty or just "dos".)

Trailing ^M characters mean that the file has mixed ends-of-lines 
(assuming that 'fileformats' [plural] contains both "unix" and "dos"). 
Often, such a file actually has CR+LF throughout, except on the last 
line which has nothing at all.


Best regards,
Tony.
-- 
If only God would give me some clear sign!  Like making a large deposit
in my name at a Swiss bank.
                -- Woody Allen, "Without Feathers"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to