Saturday, November 16, 2019

Re: Trailing ^M on Windows

On Windows, when you read a file in Vim and every (or almost every)
line ends with ^M, it usually means that the last line lacks an
end-of-line, which made Vim read the whole file as if it were a Unix
file. This is how I would fix such a file:

:new ++ff=dos filename.ext
:wq

(this has the side-effect of opening then closing a new window for
that file) — see ":help ++opt".
Reading the file with 'fileformat' explicitly set to dos forces both
CR+LF or LF alone (or nothing at end of file) to be recognised as
ends-of-lines. Writing the file (which still has 'fileformat' set to
dos) writes a proper CR+LF Dos/Windows end-of-line at the end of every
line including the last one, so the next time you read it it will be
recognised as a Windows file and you won't see those pesky ^M (i.e.
carriage-return) characters (they are still there but they are part of
the normal Dos/Window end-of-line).

Or if you want to transmit the file to be read on a Unix system, you
can replace :wq by :wq ++ff=unix — in that case all lines will get a
proper LF-only Unix end-of-line, which both Vim (on any platform) and
any Unix program will be able to recognise properly. In this case the
^M characters are not even there so no one will see them.

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtDBLPtAtP0MjeBOwBzJXKKf%2BYVj5VT9F_%2BqjhMQ5xiYg%40mail.gmail.com.

No comments: