set nobomb not removing byte order mark in vim
Asked Answered
A

1

6

I want to remove \xef\xbb\xbf marks (BOM) from my file. It's a text file to be fed to python, and the BOM marks are causing problems there. I tried :set nobomb but those are still there. How can I solve this problem and what might have caused this problem?

UPDATE: My file is obtained by combining (concatenating) many other files (using obabel software) each of which has BOM. So, probably set nobomb removes BOM mark only at the beginning of the new file. In such cases, how can I remove all BOMs?

Amadeus answered 4/5, 2013 at 12:21 Comment(2)
Checking the obvious first, did you save in the same session that you did the :set nobomb? From the Vim help: When you don't change the options, the BOM will be restored when writing the file. Or another possibility: was your vim config already set to nobomb by default? If so, then :set nobomb wouldn't delete the BOM character because the options wouldn't have changed.Badmouth
I saved in the same session. I looked into my vimrc file but did not find anything related to BOM.Amadeus
S
5

If the byte sequences are embedded in your buffer, a

:%substitute/\%ufeff//g

might already do the trick.

Syrinx answered 4/5, 2013 at 20:13 Comment(5)
This does not do, The patter I get <feff> is not matched to it and some variations I tried.Amadeus
@Amadeus Yep, assuming the UTF-8 filetype and proper encoding, it should probably be \%ufeff, at least that worked for me.Syrinx
It worked now, I might have made some mistake earlier. Thank you.Amadeus
What does %u mean? What are other similar encoding?Amadeus
Ah, great! %u is for a 4-digit Unicode value, %x for 2-digit byte. See :help /\%uSyrinx

© 2022 - 2024 — McMap. All rights reserved.