Loading ...
Sorry, an error occurred while loading the content.

File encoding question (UTF-16?)

Expand Messages
  • 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
    Message 1 of 3 , Aug 1 5:51 AM
    • 0 Attachment
      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
    • Tony Mechelynck
      ... From: Neil Bird To: Vim Mailing List Sent: Monday, August 01, 2005 2:51 PM Subject: File encoding question (UTF-16?)
      Message 2 of 3 , Aug 1 8:59 AM
      • 0 Attachment
        ----- Original Message -----
        From: "Neil Bird" <neil@...>
        To: "Vim Mailing List" <vim@...>
        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.
      • Neil Bird
        Around about 01/08/05 16:59, Tony Mechelynck typed ... ... Excellent, thanks for that! -- [neil@fnx ~]# rm -f .signature [neil@fnx ~]# ls -l .signature ls:
        Message 3 of 3 , Aug 1 11:49 PM
        • 0 Attachment
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.