[EMAIL PROTECTED] wrote: > "A.J.Mechelynck" <[EMAIL PROTECTED]> 写于 2007-06-06 09:51:51: >> Unicode files may or may not have a BOM, depending on who (or which > program) >> created them and where they come from. If you remove "ucs-2le" from your >> 'fileencodings', but leave "ucs-bom" at the start, any Unicode > fileshaving a >> BOM will still be recognised and the proper encoding set. >> >> >> Best regards, >> Tony. > > It seems that ucs-2le files with BOM will get recongized now. > But I've got some other question: > > 1. will vim write BOM when writing to unicode files? or is there any > options for that?
:setlocal bomb When opening a Unicode file, Vim will set or clear the buffer-local 'bomb' option according to the presence or absence of a BOM. That option is irrelevant for non-Unicode files. You can also set or clear it manually. When creating a new Unicode file from scratch, a BOM will be set, or not, depending on the corresponding global setting, so if you want your new Unicode files to be created with a BOM, you may add :setglobal bomb to your vimrc. > > 2. what is the correct way of converting a file encoding inside vim? > > I opened a file with cp936 encoding, then :set fenc=ucs-2le, then :w > newfile.txt, close the vim and open the newfile.txt with a new vim, then I > found everything in a mess. (gvim 7.1 winxp) > > -- > Sincerely, Pan, Shi Zhu. ext: 2606 > > It should have worked; but if the file had no BOM, maybe its encoding was detected wrongly: so if it was in UCS-2le but Vim thought it was in GB2312 or in cp936... "a mess" would be the result. Try opening a file in cp936 then doing :setlocal fenc=ucs-2le bomb :w Your other Vim ought to display it correctly then. See also ":help ++opt" for another way to set the 'fileencoding' for one file only. Best regards, Tony. -- Life would be so much easier if we could just look at the source code.