Vim coding problems

Source: Internet
Author: User

Gvim is smaller than Emacs and is suitable for programming. The latter has full functions, many plug-ins are loaded, and the startup is slower. Individual gvim is sufficient.

Vim can edit a variety of character encoding files, including UCS-2, UTF-8 and other popular unicode encoding methods:

Vim has four options related to character encoding: encoding, fileencoding, fileencodings, and termencoding. Their meanings are as follows:

* Encoding: the internal character encoding method used by VIM, including the buffer, menu text, and Message Text of vim;
* 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: When Vim is started, it detects the character encoding methods of the files to be opened one by one based on the character encoding methods listed in it, and sets fileencoding as the final character encoding method. Therefore, it is best to put the Unicode encoding method at the beginning of this list, and put Latin1, the Latin1 method, in the latin1;
* Termencoding: The character encoding method of the terminal (or Windows Console window) operated by VIM.

How Vim multi-character encoding works:

1. Start vim and set the encoding mode of the buffer, menu text, and message text based on the encoding value set in. vimrc;
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, this requires calling iconv. dll.

Since Unicode can contain characters in almost all languages, and the Unicode UTF-8 encoding method is very cost-effective (space consumption is less 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 ;). We recommend that you set fileencoding
Chinese (Chinese is an alias for gb2312 in UNIX, cp936 in windows, that is, GBKCodePage ).

Note 1: in fact, the test accuracy of VIM is not high, especially when encoding is not set to UTF-8. Therefore, we strongly recommend that you set encoding to UTF-8, although it may cause another minor problem if you want Vim to display chinese menus and prompt messages.

NOTE 2: You can download to iconv Win32 (http://mirrors.kernel.org/gnu/libiconv/libiconv-1.9.1.bin.woe32.zip) on gnu ftp ).

NOTE 3: View help: H iconv-dynamic.

NOTE 4: The. vimrc mentioned above is _ vimrc in windows and exists in the vim installation directory.

The following is the configuration file _ vimrc in gvim7.2 in Windows. Using this configuration can solve the problem of Garbled text such as menus and console information after the Chinese version of vimdoc is installed.
Set encoding = UTF-8
Set fileencodings = UTF-8, Chinese, Latin-1
If has ("Win32 ")
Set fileencoding = Chinese
Else
Set fileencoding = UTF-8
Endif
Source $ vimruntime/delmenu. Vim
Source $ vimruntime/menu. Vim
Language messages zh_CN.utf-8

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.