Configure. vimrc to solve the problem of VIM/gvim character encoding in Chinese Windows

Source: Internet
Author: User

Vim/gvim character encoding in Chinese Windows has two problems:

    1. No encoding detection function by default
    2. 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:

    1. Garbled characters when using Vim on non-Gui Interfaces
    2. Prompt information (suchE492: 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 ).
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.