Explanation of VIM encoding and Chinese Environment Settings

Source: Internet
Author: User
As a loyal user of VIM, I learned from help more than two years ago: Edit.
++ ENC = xxx, I have never learned about Vim encoding settings. Over the years, I have encountered encoding errors, always: Edit
++ ENC = xxx. Today: I helped encoding and so on, and finally figured out the functions and relationships of the relevant variables.
In short, there are three settings. (The following is a description of the Chinese environment)
1) Add set in. vimrc or _ vimrc.
Fileencodings = UTF-8, gb2312, GBK, gb18030, and big5 are basically OK. Vim uses these encodings to encode the files in sequence.
2) If the problem persists, use: Edit after opening the file.
++ ENC = GBK: This Command forces a certain encoding.
3) if the problem persists, check your $ Lang environment variables.
The following is a detailed description.
Vim encoding mainly involves three variables.
Encoding
Vim internal encoding, including memory data encoding and VIM configuration file encoding. Encoding is taken from the variable $ Lang. If $ Lang is null, Latin1 is used. This encoding should be consistent with your terminal encoding.
Fileencoding
File encoding. Vim converts the encoding to the encoding of the encoding parameter when loading the file. Similarly, when saving files, the memory encoding will be changed from encoding to fileencoding.
Note that setting this parameter in vimrc does not work. When opening a file, fileencodings or encoding will overwrite fileencoding. For more information, see the file opening process mentioned below.
Fileencodings = UTF-8, GBK, gb2312
When loading a file, VIM tries to use the encoding in fileencodings as fileencoding in sequence. If all fails, VIM uses Encoding As fileencoding.
In addition, if Vim uses an error code, you can use Edit
++ ENC = GBK. It means to re-read the file and forcibly use GBK as fileencoding. Filencodings is ignored.
The following are the internal processes for some Vim operations:
Open a file
First, read data from the file to the memory, and then use each encoding from fileencodings to try to convert it to encoding. If one is successful, stop the attempt. If not, encoding is used as fileencoding. That is to say, there is a process of converting from fileencoding to encoding.
Save files
Convert the memory data from encoding to fileencoding, and then write the data to the file.
In fact, the difference between encoding and fileencoding is the most confusing thing here. This is because encoding does not need to be set in most guis, especially in Windows editors. Generally, this encoding is consistent with the encoding in the GUI environment by default. Encoding is the storage encoding of data in the memory, while fileencoding is the file encoding.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.