Home >Operation and Maintenance >Linux Operation and Maintenance >Introduction to solutions to garbled characters in Linux
When logging in to the Linux server remotely and using vim to edit and view files in the terminal, various Chinese garbled problems often occur.
The following settings can basically solve the vim Chinese garbled problem
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 Chinese encoding files in the list, such as To recognize Chinese files of other encoding types, you need to upgrade the system
vi ~/.bash_profile
Add
export LANG="zh_CN.UTF at the end of the file -8"
export LC_ALL="zh_CN.UTF-8"
Online video tutorial recommendation: linux video tutorial
vim and Encoding-related parameters:
1. eencoding is used to configure the encoding of opening files and saving files, but it can only have one value. It is only suitable for environments where a few files have the same encoding, so it is generally not used
2. Fileencodings, as you can tell from the name, 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 used by vim For correct reading, 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, but not 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. Most of them are utf-8 under Linux, and gdk under Chinese 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. The default is consistent with the language encoding of the operating system. If you use the linux command terminal, it is recommended that the terminal and the linux system have the same configuration. Encoding, and then configure the same termencoding, otherwise vim will not take care of the shell. However, if the shell does not have a Chinese name file, just configure the terminal and termencoding to be consistent. For windows, gbk and utf-8 can be automatically recognized, no need Special configuration, recommended configuration: set termencoding=utf-85, fileformats, used to distinguish operating systems, mainly the difference of carriage return\r\n, recommended configuration: set fileformats=unix,dosCommon garbled characters include the following situations:
(1) When rz files from Windows environment to Linux, the files appear garbled## to the last line
set fileencoding=gb2312
set termencoding=utf-8
The above is the detailed content of Introduction to solutions to garbled characters in Linux. For more information, please follow other related articles on the PHP Chinese website!