File encoding question (UTF-16?)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

File encoding question (UTF-16?)

Neil Bird

   I think I asked this years ago, but I've lost & forgotten the answer!

   I have a file (previously on Win32, but this was on Linux IIRC - I've
actually forgotten at this moment what it was!) that seems to have 16-bit wide
chars:  every character is actually preceded by a nul:

   hello  ->  ^@h^@e^@l^@l^@o


   Is there some combination of encoding/fileencoding/other  can set to get it
editable?  I'm running natively UTF-8.

--
[neil@fnx ~]# rm -f .signature
[neil@fnx ~]# ls -l .signature
ls: .signature: No such file or directory
[neil@fnx ~]# exit
Reply | Threaded
Open this post in threaded view
|

Re: File encoding question (UTF-16?)

A.J.Mechelynck
----- Original Message -----
From: "Neil Bird" <[hidden email]>
To: "Vim Mailing List" <[hidden email]>
Sent: Monday, August 01, 2005 2:51 PM
Subject: File encoding question (UTF-16?)


>
>   I think I asked this years ago, but I've lost & forgotten the answer!
>
>   I have a file (previously on Win32, but this was on Linux IIRC - I've
> actually forgotten at this moment what it was!) that seems to have 16-bit
> wide chars:  every character is actually preceded by a nul:
>
>   hello  ->  ^@h^@e^@l^@l^@o
>
>
>   Is there some combination of encoding/fileencoding/other  can set to get
> it editable?  I'm running natively UTF-8.
>
> --
> [neil@fnx ~]# rm -f .signature
> [neil@fnx ~]# ls -l .signature
> ls: .signature: No such file or directory
> [neil@fnx ~]# exit
>
>
>

    Your file is in little-endian UTF-16. With 'encoding' set to UTF-8, load
it using

    :e ++enc=utf-16le filename

If the first two bytes in the file are 0xFF 0xFE (the UTF-16le encoding
marker, also known as the BOM for "byte order mark"), then the encoding can
be recognised automatically if your 'fileencodings' start with ucs-bom
(i.e., with ":set fencs^=ucs-bom"). -- Normally, if your 'encoding' is set
to UTF-8, 'fileencodings' should be set to something like
"ucs-bom,utf-8,default" (for Vim 7) or "ucs-bom,utf-8,latin1" (for Vim6,
replace "latin1" by the 8-bit encoding you use most often).

See
    :help ++opt
    :help mbyte-encoding
    :help encoding-values
    :help 'fileencodings'
        /"ucs-bom"
    :help 'bomb'
        especially the last paragraph
    :help :set^=

HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: File encoding question (UTF-16?)

Neil Bird
Around about 01/08/05 16:59, Tony Mechelynck typed ...
>    :e ++enc=utf-16le filename

   Excellent, thanks for that!

--
[neil@fnx ~]# rm -f .signature
[neil@fnx ~]# ls -l .signature
ls: .signature: No such file or directory
[neil@fnx ~]# exit