Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6371583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:05:37+00:00 2026-05-25T01:05:37+00:00

I need a file that I want to make sure is encoded with utf8

  • 0

I need a file that I want to make sure is encoded with utf8.

So, I create the file

c:\> gvim umlaute.txt

In VIM I type the Umlaute:

äöü

I check the encoding …

:set enc

(VIM echoes encoding=latin1)

and then I check the file encoding …

:set fenc

(VIM echoes fileencoding=)

Then I write the file

:w

And check the file’s size on the harddisk:

!dir umlaute.txt

(The size is 5 bytes) That is of course expected, 3 bytes for the text and 2 for the \x0a \x0d.

Ok, so I now set the encoding to

:set enc=utf8

The buffer get’s wierd

<e4><f6><fc>

I guess this is the hex representation of the ascii characters I previously typed in. So I rewrite them

äöü

Writing, checking size:

:w
:$ dir umlaute.txt

This time, it’s 8 bytes. I guess that makes sense 2 bytes for every character plus \x0d \x0a.

Ok, so I want to make sure the next time I open the file it will be opened with encodiung=utf8.

:setb
:w

:$ dir umlaute.txt

11 Bytes. This is of course 8 (previous) Bytes + 3 Bytes for the BOM (ef bb bf).

So I

:quit

vim and open the file again

and check, if the encoding is set:

:set enc

But VIM insists its encoding=latin1.

So, why is that. I would have expected the BOM to tell VIM that this is a UTF8 file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:05:38+00:00Added an answer on May 25, 2026 at 1:05 am

    You are confusing 'encoding' which is a Vim global setting, and 'fileencoding', which is a local setting to each buffer.

    When opening a file, the variable 'fileencodings' (note the final s) determines what encodings Vim will try to open the file with. If it starts with ucs-bom then any file with a BOM will be properly opened if it parses correctly.

    If you want to change the encoding of a file, you should use :set fenc=<foo>. If you want to remove the BOM you should use :set [no]bomb. Then use :w to save.

    Avoid changing enc after having opened a buffer, it could mess up things. enc determines what characters vim can work with, and it has nothing to do with the files that you are working with.

    Details

    c:\> gvim umlaute.txt

    You are opening vim, with a nonexistent file name. Vim creates a buffer, gives it that name, and sets fenc to an empty value since there is no file associated with it.

    :set enc

    (VIM echoes encoding=latin1)

    This means that the Vim stores the buffer contents in ISO-8859-1 (maybe another number).

    and then I check the file encoding …

    :set fenc

    (VIM echoes fileencoding=)

    This is normal, there is no file for the moment.

    Then I write the file

    :w

    Since 'fileencoding' is empty, it will write it to the disk using the internal encoding, latin1.

    And check the file’s size on the harddisk:

    !dir umlaute.txt

    (The size is 5 bytes) That is of course expected, 3 bytes for the text and 2 for the \x0a \x0d.

    Ok, so I now set the encoding to

    :set enc=utf8

    WRONG! You are telling vim that it must interpret the buffer contents as UTF8 content. the buffer contains, in hexadecimal, e4 f6 fc 0a 0d, the first three bytes are invalid UTF8 character sequences. You should have typed :set fenc=utf-8. This would have converted the buffer.

    The buffer get’s wierd

    That’s what happens when you force Vim to interpret an illegal UTF-8 file as UTF8.

    I guess this is the hex representation of the ascii characters I previously typed in. So I rewrite them

    äöü

    Writing, checking size:

    :w
    :$ dir umlaute.txt

    This time, it’s 8 bytes. I guess that makes sense 2 bytes for every character plus \x0d \x0a.

    Ok, so I want to make sure the next time I open the file it will be opened with encodiung=utf8.

    :set bomb
    :w

    :$ dir umlaute.txt

    11 Bytes. This is of course 8 (previous) Bytes + 3 Bytes for the BOM (ef bb bf).

    So I

    :quit

    vim and open the file again

    and check, if the encoding is set:

    :set enc

    But VIM insists its encoding=latin1.

    You should run set fenc? to know what is the detected encoding of your file. And if you want Vim to be able to work with Unicode files, you should set in your vimrc that 'enc' is utf-8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do XMLParsing in c(windows). for that i need the libxml/xmlversion.h file.
I have a .txt file that I need to include into a page, that
I need to create a single trace file that spans several days for one
I need to create a batch file that reads a file with one line
I need to create a batch file that changes path to a particular folder
I want to make sure that an image in my application is not more
I want to make sure a CSV file uploaded by one of our clients
I need a batch file that will search for the string Gen_1_X. When the
I have an Excel file that I need to import into a (new) Oracle
I need to read the data from a file that can be either comma

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.