On 19/09/12 16:24, rudra wrote:
An annoying ^M at the end of each line, or at the end of each line
except the last one?
It is a common defect of many ill-conceived Windows editors, that they
fail to put a proper end-of-line at the end of the last line. In that
case, Vim doesn't see the file as being in "dos" fileformat, because one
of the lines (the last one) lacks a DOS/Windows-like end-of-line. It
opens the file as "unix" fileformat then, with a visible ^M at the end
of every line except the last. This ensures that any line which ended in
CR+LF will keep it, and that any line which ended in LF only won't get
an added CR before it.
To "repair" the file and make sure that every line, including the last
one, ends in CR+LF, open it with ++ff=dos (see :help ++opt)
either (if the file was already open in Vim)
or (if it wasn't)
:e ++ff=dos filename.ext
++ff=dos will regard either CR+LF or LF-alone as an end-of-line, and
regard the file as being in "dos" fileformat. (This requires Vim 7.2.040
or later; if you still have an earlier version, I recommend that you
upgrade ASAP the latest published version of the sources is 7.3.666.)
This won't help if one or more lines end in CR+CR+LF (i.e. with two or
more carriage-returns before the linefeed). In that case, write the file
as unix and reopen it as dos to eliminate one level of spurious carriage
returns. Or else, if you have lines with many carriage-returns at the end,
:w " optional - you may do it later on
will eliminate any number of carriage-returns except one (and add one if
there were none) immediately before the linefeed at the end of a line.
ARTHUR: I command you as King of the Britons to stand aside!
BLACK KNIGHT: I move for no man.
The Quest for the Holy Grail (Monty