Solve the Linux vim Chinese garbled method _linux

Source: Internet
Author: User

A detailed introduction to VIM coding

Vim, like all popular text editors, is a good way to edit a variety of character-encoded files, including, of course, popular Unicode encodings such as UCS-2 and UTF-8.

Vim has four options related to character encoding, encoding, fileencoding, fileencodings, termencoding (these options may be taken, please refer to vim online Help: Helping Encoding-names), Their significance is as follows:

1, Encoding:vim internal use of the character encoding method, including Vim (buffer), menu text, message text and so on. The user's manual suggests changing its value only in. VIMRC, and in fact it seems only meaningful to change its value in. vimrc.

2, Fileencoding:vim the current editing of the file character encoding, Vim save the file will also save the file as this character encoding (whether or not the new file is so), the Internet is introduced, But I did it in. VIMRC defined as Utf-8 seems to have no effect, only when the vim file open the manual settings will be effective, do not know why.

3. When Fileencodings:vim starts, it detects the character encoding of the file that will be opened in accordance with the character encoding it lists, and sets the fileencoding to the final detected character encoding. So it's best to put the Unicode encoding at the top of this list, and put the Latin coding latin1 on the last side.

4. The character encoding method of the terminal (or Windows Console window) that Termencoding:vim works with. This option is not valid for the gVim of our commonly used GUI schemas under Windows, and for Vim in console mode is the code page for the Windows console, and usually we don't need to change it.

Let's take a look at how Vim's multiple character encoding support works.

1, Vim starts, according to the encoding value which sets in the. VIMRC, sets the buffer, the menu text, the message text character encoding way.

2, read the file to be edited, according to the character encoding listed in Fileencodings to detect the file encoding method. and set fileencoding to detect what appears to be the correct character encoding, and if no appropriate encoding is found, open with latin-1 (ASCII) encoding.

3, contrast fileencoding and encoding values, if the difference is called Iconv the file content into encoding description of the character encoding, and put the converted content into this file into the buffer, at this time we can start editing this file.

4, when the editor is finished saving the file, compare the values of fileencoding and encoding again. If different, call Iconv to convert the text in the upcoming buffer to the character encoding described by fileencoding and save it to the specified file.

Because Unicode can contain almost all of the language's characters, and Unicode's UTF-8 encoding is a very cost-effective way to encode (space consumption is smaller than UCS-2), the recommended encoding value is set to Utf-8. Another reason to do this is that Vim automatically detects files in a more accurate way when encoding is set to Utf-8 (perhaps the main;). The files we edited in Chinese Windows, in order to accommodate compatibility with other software, the file encoding or set to GB2312/GBK is more appropriate, so the fileencoding recommendation is set to Chinese (Chinese is an individual name, in the Unix representation gb2312 , which represents cp936 in Windows, which is the code page for GBK.

Solution to the Linux vim Chinese garbled method

1, download

Download the latest 7.3 version of Vim source to http://www.vim.org/.

2, installation

Before compiling, look at the ./configure --help configuration options,

This configuration needs to be added in:--enable-multibyte      Include multibyte editing support

The role is to support multibyte encodings, which should be important. Otherwise, the configuration seems to be useless, I do not know if I said right.

After the disposition is good, the nature is regular: make , make install the

3, the last is the VIMRC script configuration

Edit ~/.vimrc the file, plus the following lines:

 Set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set
 termencoding=utf-8
 set Encoding=utf-8

can be done.

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, if there is doubt you can message exchange, thank you for the cloud Habitat Community support.

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.