Vim Character Set problem

Source: Internet
Author: User

Using the Vim text editor in CentOS, there is a problem with Chinese garbled characters.

The problem of any character garbled is caused by the problem of character set mismatch. The character set mismatch here is only a mismatch between the encoding and decoding of the file, and may involve more than one decoding process.

All files in the computer are stored in binary format (computer-readable content). When we read the contents of the file, it is read by different software, when the software reads the contents of the file, it needs to use different character sets to identify the human identifiable content in the file. A character set is a comparison between a numeric value and a human identifiable base character.

A file has its own coded character set, and the editor has its own character set when reading the file, and the display character set of the terminal is also involved in the Linux system.

When using VIM to open a file in the Xshell terminal, Chinese characters are garbled. Analysis reasons to consider: 1. The original encoding of the file 2.vim open the file encoding Method 3. The encoding method of the Xshell terminal.

There are three main variables related to character sets in Vim: Encoding (ENC), fileencoding (Fenc), Fileencodings (Fencs).

Fileencodings: A guessing list that decodes when a file is opened.

fileencoding: Used to set the character set used when saving files.

Encoding: Used to set the character set used when editing a file.

For example, you can use the following command

1.: edit ++enc=<encoding> [filename] to reopen the file in the specified encoding format. That is, edit the file under this character set.

2.: Write ++enc=<encoding> [filename] Saves the file in the specified encoding format.

Both of these methods can temporarily overwrite the default edits specified in the bottom 3.4 two ways, the default character set when writing.

3.: set Encoding[=<encoding>] Specifies the character set of the edit file. (when displayed)

4.: set Fileencoding[=<encoding>] Specifies the character set for saving the file. (When writing)

Vim in opening a file is first guessing the correct character set based on the character set category in the variable fileencodings, and then setting the fileencoding variable to the selected character set. If Fileencodings is not set, select Use the system's character set (locale command to view). The fileencoding is then set to this encoding.

Using VIM to open a file, you can use [: Set Fileencodings], [: Set fileencoding], [: Set encoding] To view the configuration information for the current variable.

Configure Vim's three variables in CentOS:/ETC/VIMRC file.

Reference articles:

https://spin.atomicobject.com/2011/06/21/character-encoding-tricks-for-vim/

Http://www.itnose.net/detail/6487670.html

Http://stackoverflow.com/questions/16507777/vim-set-encoding-and-fileencoding-utf-8

Http://stackoverflow.com/questions/1174847/how-to-set-the-character-encoding-for-a-file-in-vim

Http://www.cnblogs.com/ggjucheng/archive/2012/01/04/2312522.html

Http://www.cnblogs.com/jacklikedogs/p/3494566.html

Http://www.joelonsoftware.com/articles/Unicode.html

Http://blog.sina.com.cn/s/blog_912de1360102wm5p.html

Vim Character Set problem

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.