Vim display Utf-8 Document garbled solution method

Source: Internet
Author: User

A detailed introduction to VIM coding

Vim, like all popular text editors, can edit a wide variety of character-encoded files, which of course includes popular Unicode encoding methods such as UCS-2 and UTF-8.

Vim has four options related to character encoding, encoding, fileencoding, Fileencodings, termencoding (the possible values for these options can be found in the VIM online assistance: Help Encoding-names), They have the following meanings:

1, Encoding:vim internal use of the character encoding method, including Vim buffer (buffers), menu text, message text and so on. The user manual recommends changing its value only in. VIMRC, which in fact seems to only make sense if you change its value in. vimrc.

2, Fileencoding:vim in the current editing of the character encoding of the file, Vim saves the file will also save the file as such character encoding method (whether or not new files are so), the internet is described, But what I do in. VIMRC is defined as Utf-8 does not seem to work, only when the vim file is opened manually set to be effective, do not know what the reason.

3. Fileencodings:vim starts by detecting the character encoding of the file that is about to be opened by the character encoding it lists, and sets the fileencoding to the final detected character encoding method. It is therefore best to place Unicode encoding at the top of this list, Latin1 Latin encoding to the last side.

4. The character encoding of the terminal (or the Console window of Windows) to which Termencoding:vim works. This option is not valid for the gVim of our common GUI mode under Windows, and for Vim of the console mode is the code page of the Windows console, and usually we do not need to change it.

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

1, Vim start, according to the encoding value set in the. VIMRC to set the buffer, menu text, message text character encoding method.

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

3, compare the values of fileencoding and encoding, if different call Iconv to convert the contents of the file to encoding the character encoding described, and put the converted content into the buffer opened for this file, we can begin to edit this file.

4. When you save the file after editing, compare the values of fileencoding and encoding again. If it is different, call Iconv again to convert the text in the saved buffer to the character encoding described by fileencoding and save it to the specified file.

Because Unicode can contain characters in almost all languages, and Unicode's UTF-8 encoding is a very cost-effective encoding (less space consuming than UCS-2), it is recommended that the value of encoding be set to Utf-8. Another reason for this is that when encoding is set to Utf-8, the Vim Auto-detect file is encoded more accurately (perhaps this is the main;). We are editing files in Chinese Windows, in order to take into account the compatibility with other software, file encoding or set to GB2312/GBK more appropriate, so fileencoding recommended set to Chinese (Chinese is an individual name, in Unix represents gb2312 , which in Windows represents cp936, the code page for GBK).

How to solve the Chinese garbled characters of vim under Linux

1. Download

The latest 7.3 version of Vim source can be downloaded to http://www.vim.org/.

2. Installation

Before compiling, you need to ./configure --help look at the configuration options before

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

Its role is to support multibyte encoding, which should be important. Otherwise the configuration seems to be useless, I do not know that I am right.

After the configuration has been done, nature is normal: make  , make install

3. Finally, the VIMRC script is configured

Edit the/ETC/VIM/VIM/VIMRC 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.

Vim display Utf-8 Document garbled solution method

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.