On Oct 18, 5:44 pm, bgold12 <[EMAIL PROTECTED]> wrote:
> How can I change the format of a text file that I'm editing in vim?
>
> I recently saved the source code of a web page and opened it in vim,
> and it said at the bottom [unix], which I assume means vim decided for
> some reason that this is a "Unix" file (or should be viewed as a Unix
> file), however every line ends with the CR symbol, ^M, so this is
> obviously a "Windows" file.
>
> I know I can do a simple substitution of all ^M's with nothing to get
> rid of them (assuming there are no other ^M's in the file that I
> wouldn't want to get rid of), but I'd also like to know if I can
> change that setting (the vim file format display) myself. Also, why
> wasn't vim able to recognize that the file was separated by CR/NL
> instead of just NL?

I always fix it this way, while the file is open:

:%s/\r//
:set ff=dos
:w

As for what causes it, Vim is perfectly capable of detecting DOS/
Windows-style line endings, but only if _every_ line in the file has
them. If even 1 line does not have the proper line ending, the file is
treated as Unix so that you can see all the contents of the file.

Many editors in Windows have been designed so that when pasting lines
from a file with one style of line ending into a file with another
style, no conversions will be made. This is probably the most frequent
source I've seen for the problem. Someone will copy some lines from a
Unix-style file into a Windows file, and not realize what happened
because their editor cannot differentiate between the two line
endings. Visual Studio I think just does this blindly. Ultraedit has a
setting (disabled by default!) that will automatically convert the
line endings. Other editors may or may not do things more
intelligently depending on their settings.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to