I see

alt text

where all contents is in one line.

It seems that this is the reason of bad encoding. I can see the characters ^M.

How can you get the encoding right in Vim?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Try:

:set fileformats=unix,dos,mac

Then reread your file with :e.

link|improve this answer
@Greg: Thank you for your answer! – Masi Jul 4 '09 at 11:09
I opened another similar question at serverfault.com/questions/35900/… – Masi Jul 4 '09 at 16:51
feedback

These are "line breaks", or newlines.

From your screenshot it seems the file uses Mac-style line breaks, which are a single carriage return (0x0D, in the screenshot shown as ^M).

Windows (and most of the Internet protocols) use both carriage return and line feed (0x0D 0x0A), and Unix uses a single line feed (0x0A) to separate lines. Macs used to only use carriage returns (now Unix-style is common on MacOS X too).

In vi/vim, try this command to make it recognize the file:

:set ff=mac

You can try using this command to convert the file to Windows-style line breaks:

sed "s/\x0D/\x0D\x0A/g" yourfile.html > yourfile.new.html
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.