The encoding in VIM is mainly related to three parameters: ENC (encoding), fenc (fileencoding), and fencs (fileencodings)
Fenc is the encoding of the current file, that is, a file that has been correctly displayed in VIM (the premise is that your system environment matches your ENC settings ), you can change fenc and then W to save the file into different encodings. For example, I: Set fenc = UTF-8 and then: W will save the file as UTF-8, And: Set fenc = gb18030 and then: W will save the file as gb18030. This value does not matter whether the file can be correctly decoded when it is opened.
Fencs is a list of guesses used to decode a file when it is opened. File encoding is not correct, so Vim can only guess the file encoding.
The function of ENC is to show that, no matter what encoding the final file is, VIM will convert it to the current system encoding for processing, so that it can be correctly displayed in the current system, therefore, ENC does this. In Windows, the default value of ENC is cp936, which is the default encoding of Chinese Windows. Therefore, ENC does not need to be changed. In Linux, as your system locale may be set to zh_cn.gb18030 or zh_CN.utf-8, your ENC should be set to gb18030 or UTF-8 (or GBK ). And I encountered the system locale is a en_US.UTF-8, do not set ENC explicit Chinese, and finally configure ENC for UTF-8 to explicit.
Finally, the Linux encoding is all UTF-8, VIM can display the Chinese vimrc file Configuration:
SetFileencodings = UTF-8, Gb2312, GBK, gb18030, big5
SetFenc = UTF-8
SetENC = UTF-8