On 20/10/08 16:22, fritzophrenic wrote:
>
>
> 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//

This will delete carriage -returns anywhere in the file, but only the 
first one if there are several on a line. You may prefer

        :%s/\r$//

to remove only carriage-returns at end-of-line. (Some programs such as 
rsync use carriage-returns without line-feed on sysout to erase the 
current line without going to the next line; these "naked CRs" are 
visible when redirecting the program's output to a logfile.)

> :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.
[...]

You may also force-read with one specific type of line endings, but it 
will only work if 'fileformats' (plural) is empty: see ":help ++opt". 
The "dos" fileformat will then treat _either_ CR+LF or LF alone as and 
end-of-line when reading, and will write CR+LF when writing.

For instance

        command -bang -bar -nargs=? -complete=file EditAsDos
                \ call EditAsDos(<q-args>,<q-bang>)
        function EditAsDos(file,bang)
                let save_ffs = &ffs
                set ffs=
                exe "edit" . a:bang "++ff=dos" a:file
                let &ffs = save_ffs
        endfunction


Best regards,
Tony.
-- 
It will be generally found that those who sneer habitually at human
nature and affect to despise it, are among its worst and least pleasant
examples.
                -- Charles Dickens

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

Reply via email to