Linux all kinds of Chinese garbled solution sorting __linux

Source: Internet
Author: User

Remote login server with VIM in the Terminal editor to view files often meet a variety of Chinese garbled problems.
To do the following settings can basically solve the problem of vim Chinese garbled

First check the system's support for Chinese
locale-a | grep ZH_CN

Output samples such as the next
Zh_cn.gbk
Zh_cn.utf8

Vim can only correctly identify the Chinese encoded files in the list, if you need to identify other encoding types of Chinese files, you should do system upgrades

VI ~/.bash_profile
Add at end of file

Export lang= "ZH_CN. UTF-8 "

Export Lc_all= "ZH_CN. UTF-8 "

Vim's encoding-related parameters: fileencoding, which is used to configure the encoding for opening and saving files, but only a single value suitable for a small number of files that are encoded in the same environment, so generally do not use fileencodings, From the name to see that is FileEncoding's enhanced version, you can configure a variety of different encodings, the common configuration for, after the configuration, the list of text encoding as long as legitimate, can be vim correct reading, recommended configuration: Set Fileencodings=utf-bom, Utf-8,gbk,gb2312,gb18030,cp936,latin1 encoding,vim Internal encoding, vim reads the file, but does not process it by reading the file's encoding, but converts it into an internally encoded format that is generally related to the operating system. Linux under the majority of Utf-8, Chinese Windows is GDK, recommended configuration: Set Encoding=utf-8 termencoding,vim output encoding, output refers to the output to the operating system or command terminal, the default and the operating system language coding consistent, If you use the Linux command terminal, it is recommended that the terminal and Linux system configure the same encoding, and then configure the same termencoding, otherwise the VIM will be ignored shell, but if the shell does not exist in Chinese name files, then configure the terminal and Termencoding consistent, for Windows, can automatically identify GBK and utf-8, without special configuration, recommended configuration: Set Termencoding=utf-8 fileformats, used to differentiate the operating system, mainly the difference between the carriage return \ r \ n, Recommended configuration: Set Fileformats=unix,dos

Common garbled has the following several situations

(1) The Windows environment under the file RZ to Linux files appear garbled

Solution: 1. Use notepad++ to convert the file format to UTF-8 no BOM format or ANSI code format before RZ; 2.set Encoding=utf-8;

(2) SecureCRT or XTERM2 editing environment garbled, only in the session option to adjust the character encoding for GB2312 or UTF-8

(3) When the log file for Vim editing appears garbled, in most cases because the format of the log file is GB2312.

Solution: 1.set encoding=gb2312;2 If scenario 1 does not work, adjust the editing environment for SECURECRT or Xterm2 to GB2312

(4) wget download file name garbled

Solution: Generally add –restrict-file-names=nocontrol, such as wget--restrict-file-names=nocontrol-m www.xxx.com/

(5) Cat file Normal, vim file is not normal

Solution: Write directly to/ETC/VIM/VIMRC, the last line plus set fileencodings=gb2312,utf-8 set fileencoding=gb2312 set Termencoding=utf-8


Batch file transcoding command: iconv-c-F gbk-t utf-8 $data _path/$item _uv

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.