Various Chinese garbled solutions in Linux

 

When using vim to log in to the server remotely and edit and view files under the terminal, various Chinese garbled characters are often encountered.
Doing the following settings can basically solve the problem of vim Chinese garbled characters

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

The output sample is as follows
zh_CN.gbk
zh_CN.utf8

vim can only correctly recognize the Chinese encoding files in the list. If you need to recognize Chinese files of other encoding types, you need to do a system upgrade

Add at the end of vi ~/.bash_profile
file

export LANG="zh_CN.UTF-8"

export LC_ALL="zh_CN.UTF-8"

 

vim encoding-related parameters:

  1. fileencoding is used to configure the encoding for opening and saving files, but it can only have one value. It is only suitable for environments where a few files are of the same encoding, so it is generally not used.
  2. fileencodings, from the name, it is known that it is an enhanced version of fileencoding. It can be configured with a variety of different encodings. The common configuration is that after configuration, as long as the text encoding in the list is legal, it can be read correctly by vim. It is recommended to configure :set fileencodings=utf-bom,utf-8,gbk,gb2312, gb18030,cp936,latin1
  3. encoding, vim internal encoding, after vim reads the file, it will not be processed by the encoding of the read file, but will be converted into an internal encoding format. This encoding is generally related to the operating system. Under linux, utf-8 is mostly, Chinese It is gdk under windows, it is recommended to configure: set encoding=utf-8 
  4. termencoding, the encoding of vim output, output refers to output to the operating system or command terminal, etc. The default is the same as the language encoding of the operating system. If you use the linux command terminal, it is recommended that the terminal and the linux system configure the same encoding, and then configure the same termencoding, otherwise If you take care of vim, you can't take care of the shell, but if the shell does not have a Chinese name file, you can configure the terminal and termencoding to be consistent. For windows, gbk and utf-8 can be automatically recognized without special configuration. It is recommended to configure: set termencoding= utf-8
  5. fileformats, used to distinguish operating systems, mainly the difference between carriage return \r\n, it is recommended to configure: set fileformats=unix,dos

Common garbled codes are as follows:

 (1) When the file rz in the windows environment is transferred to linux, the file appears garbled

        Solution: 1. Use notepad++ to convert the file format to UTF-8 without BOM format or ANSI encoding format before rz; 2.set encoding=utf-8;

 (2) Garbled characters appear in the secureCRT or xterm2 editing environment, just adjust the character encoding to GB2312 or UTF-8 in the session options

 (3) Garbled characters appear when vim editing the log file, in most cases because the format of the log file is GB2312.

        Solution: 1.set encoding=GB2312; 2 If solution 1 does not work , adjust the editing environment of secureCRT or xterm2 to GB2312

  (4) wget download file name garbled

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

  (5) The cat file is normal, the vim file is abnormal

      Solution: write directly to /etc/vim/vimrc, add the last line

  1. set fileencodings=gb2312,utf-8  
  2. set fileencoding=gb2312  
  3. set termencoding=utf-8  

 

 

Batch file transcoding command: iconv -c -f gbk -t utf-8 $data_path/$item_uv

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325295976&siteId=291194637