On 19/09/11 11:42, Ron Aaron wrote:
I'm working in a mixed environment, and many of my co-workers use
(bad) editors on Windows. So we have a number of files with a mix of
CR-LF and plain LF in them. "vim" always displays these with a "^M".
I can get rid of that by just doing ":%s/^M//", but then I change the
file, and I don't want to do that. It is also impossible for me to
enforce file format conventions.
Therefore I wonder if there is at least some way to just not display
the trailing "^M", since it is "visual noise" for the most part and
doesn't cause any other tools we use any problems.
Thanks,
Ron
Any file with a mixture of CR+LF and LF-only endings is going to cause
trouble for almost anyone using it.
If you open a file to edit it (i.e., you're going to change it anyway)
and see the ^M at the ends of lines, then if I were you I would take one
of the following choices (assuming the "bad" file is the current
editfile and has no more than one ^M at the end of each line):
a) repair the file to all-Dos (all-CR+LF) which Vim (using ":set
fileformats=dos,unix" or similar, which is the default) will
henceforward edit without displaying the ^M characters (which are there):
:e ++ff=dos
" do some more editing ) repeat any number
:w " optional ) of times
" do some more editing
:x " save the file and close its Vim window
b) repair it to all-Unix (all-LF-without-CR):
:e ++ff=dos
:setlocal ff=unix
" then do some more editing etc., as above
This second case is preferred for Vim scripts to be exchanged between
Windows and Unix, or for other texts (e.g. Mozilla sources) to be used
under both Windows and Unix, but on Windows, IIRC, Notepad cannot use
these "Unix-style" files (WordPad can). For files which will have to be
edited with Notepad, do as in (a).
Finally, a caveat: Vim will always treat as "mixed-EOL" any Dos file
whose last line is not empty and lacks any kind of end-of-line, so in
that case you'll see a ^M at the end of every line except the last,
unless you open the file with ++ff=dos (which accepts either CR+LF or
LF-only as an EOL when reading, and sets the 'filetype' of the file to
"dos" so that when writing it will write CR+LF on all lines).
See :help ++opt
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
176. You lie, even to user-friends, about how long you were online
yesterday.
--
You received this message from the "vim_dev" 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