Configuration. VIMRC solve the character encoding problem of Vim/gvim in Chinese Windows

Source: Internet
Author: User

Reprinted from:-Tiansheng's diary-NetEase Blog

There are two problems with the character encoding of Vim/gvim under Chinese Windows:

    1. No encoding detection function by default
    2. If a file itself uses a character set larger than GBK (such as UTF-8, UTF-16, GB18030), then the characters in the GBK cannot be garbled and will be lost when saved. Even if the file format is correctly detected when editing a file, it does not help.

The solution to the first problem is to add the following configuration to the ~/.VIMRC:

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

The solution to the second problem is to force the internal encoding of Vim to use some kind of UTF encoding. such as UTF-8:

set encoding=utf-8

However, setting the internal code of Vim to UTF-8 brings up the following new problems

    1. Use of Vim with non-GUI interface is garbled
    2. Hint information (e.g. E492: Command not editor: Foo) garbled

To solve the non-GUI interface of vim garbled problem, you need to set the terminal code for the system default encoding:

set termencoding=cp936

To make the message is not garbled, you need to use the UTF-8 version of the prompt message:

language messages zh_CN.UTF-8

To sum up, in the Chinese Windows correctly configured character encoding, you need to add the following content in 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

In particular, the above code should be placed at the top of the. VIMRC, because Vim set encoding=xxx is dangerous during operation and can result in various garbled characters (see here). My own use of the complete. VIMRC placed in HTTPS://SITES.GOOGLE.COM/SITE/POPATRY/ETC/-VIMRC, continuously updated.

Configuration. VIMRC solve the character encoding problem of Vim/gvim in Chinese Windows

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.