On 20/09/11 04:03, Ernie Rael wrote:
On 9/19/2011 6:18 PM, Tony Mechelynck wrote:
On 19/09/11 16:17, Ernie Rael wrote:
Suggest looking at help for 'fileformats'/'ffs' . Something like "set
fileformats=unix,dos" in your .vimrc might be what you're looking for.

-ernie

That will open correctly files whose lines are all-LF-only
(Unix-style) or all-CR+LF (Dos-style) provided in the latter case that
even the last line has a Dos-style EOF. It won't work for files with
mixed ends-of-lines (some CR+LF, others LF-only, which is what the OP
mentioned) and it will also not work on Dos-style files whose last
line lacks an EOL (i.e. Dos-style files whose last two bytes are other
than 0x0D 0x0A).

Thanks for the detailed analysis (other message) of the situation. I
discovered ":e ++ff=dos" later in the day working with a mixed CR+LF, LF
file.

Is it correct that there is no way to modify the file without looking at
the "^M" and not change the LF only line endings? I guess the "conceal"
feature is what you'd need to do.

If I open a mixed EOL file and do ":e ++ff=dos" then the file does not
become "modified". Is that a bug?

Thanks,
-ernie


I don't think so. When reading, ++ff=dos sees either CR+LF or LF-only as an end of line and replaces them by the null byte which terminates the line stored in memory as a C string. The fact that some lines had a CR before the LF and others not is regarded as insignificant in this context. When writing, Vim adds at the end of each line (in the place of the string-terminating null) the proper EOL for the current 'fileformat', i.e., CR+LF for a DOS file, LF-only for a Unix file, CR-only for a Mac file.

You can look at a file without changing it and without being bothered by the ^M characters by using

        :view ++ff=dos filename.ext

This will accept either CR+LF of LF-only as EOL when reading, and it will set 'readonly' on the file, so closing the file will normally not write it (even with 'autowriteall' which I use), and any attempt to modify it will get you a warning.

I don't understand why you would want to keep some lines with CR+LF and others with LF-only after editing it. You can do that — by treating the file as a Unix file and letting Vim display the ^M on the lines which have one. You cannot have your cake and eat it: either the presence of ^M is meaningful (and then they should be displayed) or it isn't (and writing the file as a proper Dos file actually makes it better).

If your files are kept on a version-control system (this is the only reason I can imagine to want to keep CR+LF where they are and LF-only where they are, even in the same file), maybe you could, once, convert all files to proper Dos (or Unix, but make the decision once for all) endings everywhere, and immediately add a push hook to prevent files or lines to be added with the "wrong" ends-of-lines anywhere (or with no EOL on the last line)? But of course, to do that you probably need admin privileges to the repository... If you don't have them, maybe it's time to convince an admin that mixed EOLs are unhealthy and that it's time to decide on a policy, either DOS-like EOLs everywhere (compatible with Notepad and to most Windows-only tools but not necessarily those that run under Cygwin) or Unix-like (portable, and acceptable to WordPad, Vim, and I think C etc.) but not just anything anywhere even in the same file, because _that_ is courting disaster.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
177. You log off of your system because it's time to go to work.

--
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

Raspunde prin e-mail lui