I have a UTF-16 file with a BOM. I've set fileencodings to:

set fencs=ucs-bom,utf-16le,utf-8,default,latin1    

However because of one character on one line, vim does not auto-detect UTF-16 and defaults to latin1, with all the ^@ null markers. On forcing vim to read the file as UCS (:e ++enc=ucs-bom) it reads the file successfully but reports "CONVERSION ERROR in line {nn}", but other than that one char the rest of the file has converted correctly. If the bad character is removed, the file is correctly interpreted and displayed.

Is there anyway to have vim ignore conversion errors? Forcing the encoding each time when there's a valid BOM is a bit annoying.


A conversion error means data is corrupt (or being corrupted after writing the file), so there's no global setting for ignoring those. In your case, that may be just a single, inconsequential character, but it may silently render the complete file useless in another case.

You can suppress the conversion error via the ++bad=... argument (cp. :help ++bad), which is prepended to :edit just like the ++enc=...

If you really want to suppress all conversion errors, you'd have to write a custom :EditBad command:

:command! -bar -bang -nargs=* -complete=file EditBad edit<bang> ++bad=? <args>
  • It's not so much suppress, but have the behaviour that :e ++enc has - i.e., read the file but warn about the conversion error (i.e., I want to know it's there so I can make up my own mind about the file). I'll give this a go and see what I get back. – Chris J Jun 1 '15 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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