In the past, when setting the VI encoding method, the relevant method was directly found on the internet, mainly to add the following content to the/etc/vimrc file:
Set fileencodings = UTF-8, Latin-1, gb2312, GBK, gb18030
Set termencoding = UTF-8
Set encoding = PRC
In this way, Vi can correctly display the file content in the file.
But there is a problem, that is, if you want to display the Chinese file name in VI, it will be garbled.
I previously searched for related questions on the Internet, and almost no one asked this question. Then I tolerated it for a while, but it was quite uncomfortable.
Today, I am determined to solve this problem.
After finding a lot of materials online, I finally solved the problem.
This problem mainly involves the encoding method in Vim. There are several options related to VI encoding:
Encoding, fileencoding, fileencodings, and termencoding have the following meanings:
* Encoding: the internal character encoding method used by VIM, including the buffer, menu text, and Message Text of vim;
* Fileencoding: The character encoding method of the file currently edited in Vim. When saving the file, VIM also saves the file as this encoding method (whether new files are used or not );
* Fileencodings: When Vim is started, it detects the character encoding methods of the files to be opened one by one based on the character encoding methods listed in it, and sets fileencoding as the final character encoding method. Therefore, it is best to put the Unicode encoding method at the beginning of this list, and put Latin1 In the Latin1 encoding method in the latin1 ;()
Note that the order is correct. The ucs-bom must be set to the first, UTF-8 must be the second, and Latin1 must be the last. For more information about how to configure the settings, see the vim document:
: Help fencs
* Termencoding: The character encoding method of the terminal (or Windows Console window) operated by VIM.
Because
Unicode can contain characters in almost all languages, and the Unicode UTF-8 encoding method is very cost-effective (space consumption ratio)
Small UCS-2), so we recommend that the value of encoding be set to UTF-8. Another reason for doing so is that when encoding is set to UTF-8, VIM
The automatic detection file encoding method will be more accurate (maybe this is the main reason ;). In Chinese Windows
To ensure compatibility with other software, the file encoding is set
Gb2312/GBK is suitable. Therefore, we recommend that you set fileencoding to Chinese (Chinese is an alias, which is expressed in UNIX
Gb2312 indicates cp936 in windows, that is, the GBK code page ). You can view the vim document:
:help encoding-names
Therefore, setting the vimrc file will solve the above problem:
Set fileencodings = UTF-8, Chinese, Latin-1
Set termencoding = UTF-8
Set encoding = UTF-8
Reference page: http://zengrong.net/post/1023.htm
Http://www.guizhu.net/knowledge/post/104.html