python.list at tim.thechases.com
Tue Oct 9 16:26:15 CEST 2012
On 10/09/12 07:05, Jussi Piitulainen wrote:
> Tim Chase writes:
>> However, it might be that there is no CR+LF on the last line,
>> or that one line is missing the CR, so your viewer heuristic
>> (vim does this) thinks it has Unix NL-only line-endings and
>> shows the ^M on all the lines that have the CR. All for one
>> stray line without.
> That doesn't sound robust. The problem is still quite rare for
Vim's heuristic is that, if *all* the lines end in CR+LF, it's a
DOS-formatted file; otherwise it's a Unix-style (LF) file with
spurious CRs in it (they just happen to come at the end of
most-but-not-all lines). It works quite robustly, since writing the
file back out will reliably put the CRs back where they were and
leave the non-CR'ed lines as they were with only LF. Vim makes it
pretty easy to remove the spurious CRs and then change the
file-format from Unix to DOS line-endings and write it out if that's
what you want.
which (1) removes the spurious/inconsistent CRs, (2) tells vim that
newlines should be written as CR+LF when writing and (3) writes the
file back out to disk.
More information about the Python-list