Vim/gvim character encoding in Chinese Windows has two problems:
- No encoding detection function by default
- If a file uses a Character Set Larger than GBK (such as UTF-8, UTF-16, gb18030), then the corresponding characters in the GBK will not appear garbled, will be lost when saving. Even if the file format is correctly detected during file editing, it does not help.
The solution to the first problem is in ~ /. Add the following configurations to vimrc:
Set fileencodings = ucs-bom, UTF-8, cp936, gb18030, big5, EUC-JP, EUC-KR, Latin1
The solution to the second problem is to force Vim's internal encoding to adopt a certain UTF Encoding. Such as UTF-8:
Set encoding = UTF-8
However, setting Vim's internal encoding to a UTF-8 brings about the following new problems:
- Garbled characters when using Vim on non-Gui Interfaces
- Prompt information (such
E492: not the editor command: foo
) Will be garbled
To solve the problem of VIM garbled characters on non-Gui interfaces, you need to set the terminal encoding to the system default encoding:
Set termencoding = cp936
To make the prompt information not garbled, you need to use the prompt information of the UTF-8 version:
Language messages zh_CN.UTF-8
To sum up, you must add the following content to your ~ /. Vimrc
Set fileencodings = ucs-bom, UTF-8, cp936, gb18030, big5, EUC-JP, EUC-KR, Latin1
Set encoding = UTF-8
Set termencoding = cp936
Language messages zh_CN.UTF-8
Note:CodeIt should be placed at the top of. vimrc because Vim is running
Set encoding = xxx
It is dangerous and may cause various garbled characters (see Here ).