Vim encoding method settings

Source: Internet
Author: User

Vim encoding Mode settings and all popular text editors, Vim can be very good to edit a variety of character encoding files, which of course includes UCS-2, UTF-8 and other popular Unicode encoding methods. Unfortunately, like a lot of software from the Linux world, you need to set it yourself. Www.2cto.com Vim has four character encoding options: encoding, fileencoding, fileencodings, and termencoding. For the possible values of these options, see Vim online help: help encoding-names ), their significance is as follows: * encoding: The character encoding method used inside Vim, including the buffer (buffer), menu text, and Message Text of Vim. By default, it is recommended to change the value of locale only in. vimrc in the user manual. In fact, it only makes sense to change the value in. vimrc. You can use another encoding method to edit and save files. For example, if your vim encoding is UTF-8, the edited file uses cp936 encoding, vim will automatically convert the Read File to UTF-8 (vim can read), and when you write the file, it will automatically convert it back to cp936 (the file storage encoding ). * fileencoding: The character encoding method of the file currently edited in Vim. When saving the file, Vim also saves the file as this encoding method (whether new files are used or not ). * Fileencodings: Vim automatically detects the fileencoding sequence list. At startup, it detects the character encoding methods of the files to be opened one by one based on the character encoding methods listed in it, set fileencoding to the character encoding method that is finally detected. Therefore, it is best to put the Unicode encoding method at the beginning of this list, and put latin1 in the latin1. * Termencoding: The character encoding method of the terminal (or Windows Console window) operated by Vim. If vim is encoded in the same term as vim, you do not need to set it. Otherwise, you can use the termencoding option of vim to automatically convert it to the term encoding. this option is invalid for gVim in common GUI mode in Windows, but Vim in Console mode is the code page in Windows Console, and we usually do not need to change it. Well, I have explained this pile of parameters that will easily confuse new users. Let's take a look at how Vim's multi-character encoding method supports work. 1. Start Vim and set the encoding mode of the buffer, menu text, and message text based on the encoding value set in. vimrc. Www.2cto.com 2. Read the file to be edited and test the file encoding method one by one based on the character encoding methods listed in fileencodings. And set fileencoding to the detected character encoding method, which looks correct (note 1. 3. compare the values of fileencoding and encoding. If they are different, call iconv to convert the file content to the character encoding method described by encoding, and put the converted content in the buffer opened for this file, now we can edit this file. Note: To complete this step, you need to call the external iconv. dll (note 2). You need to ensure that this file exists in $ VIMRUNTIME or other columns in the PATH environment variable directory. 4. When saving the file after editing, compare the values of fileencoding and encoding again. If different, call iconv again to convert the text in the buffer to the character encoding method described by fileencoding, and save it to the specified file. Similarly, you need to call iconv. dll because Unicode can contain characters in almost all languages, and the Unicode UTF-8 encoding method is a very cost-effective encoding method (less space consumption than UCS-2 ), therefore, we recommend that you set the encoding value to UTF-8. Another reason for doing so is that when encoding is set to UTF-8, Vim will automatically detect more accurate file encoding methods (maybe this is the main reason ;). For Files edited in chinese Windows, to ensure compatibility with other software, the file encoding is set to GB2312/GBK. Therefore, fileencoding is recommended to be set to chinese (chinese is an alias, indicates gb2312 in Unix, cp936 in Windows, that is, the GBK code page ).

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.