Thursday, February 15, 2018

Re: encoding utf-8 to utf-8[bom]

On Thu, Feb 15, 2018 at 9:54 PM, Ni Va <nivaemail@gmail.com> wrote:
> Hi Tony,
>
>
> A problem of encoding file revealed by vim :windo diff between two xml force
> me to convert the second one from utf-8[dos] to utf-8[bom][dos] but I don't
> know how to do it from within vim.
>
> Thank you in advance for your explanation.
> Nicholas.
>
>
> Nota : diff onto first utf-8[bom] and second file utf-8 fails.

• To make sure that a BOM present in a file is detected (and not
displayed as <FEFF> at the start of the file) make sure that
'fileencodings' starts with "ucs-bom"
• It is also a good idea to test for UTF-8 immediately afterwards
:set fencs-=utf-8 fencs-=ucs-bom fencs^=ucs-bom,utf-8
or (in your vimrc)
:set fencs=ucs-bom,utf-8,default,latin1
• To see if the current editfile has a BOM: ":setlocal bomb?" (the
question mark is important)
• To set a BOM on the current editfile: ":setlocal bomb"
• To clear any possible BOM the current editfile might have: ":setlocal nobomb"
• To see the 'fileencoding' and 'bomb' status of the current file on
the status line (and some other goodies) paste this into your vimrc:
if has('statusline')
set statusline=%<%f\
%h%m%r%=%k[%{(&fenc==''?&enc:&fenc)}%{(&bomb?',BOM':'')}][U+%04B]\
%-12.(%l,%c%V%)\ %P
endif
• All this assumes that 'encoding' is set to UTF-8
• The 'bomb' option has no effect on files whose 'fileencoding' is not
one of the Unicode encodings
• 'fileencoding' (singular) and 'fileencodings' (plural) are not the
same: if I use sometimes one and sometimes the other, it isn't a typo

See among others:
http://vim.wikia.com/wiki/Working_with_Unicode
:help 'fileencodings'
:help 'bomb'
:help 'statusline'
:help :set
:help ++enc

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: