Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Try:

:set fileformats=unix,dos,mac

Then reread your file with :e.

share|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
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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