Example Analysis of cat Chinese garbled Code / vim non-garbled Code or cat non-garbled Code / vim Chinese garbled Code under linux system Terminal
This article will explain in detail about linux system terminal cat Chinese garbled/vim not garbled or cat not garbled/vim Chinese garbled example analysis, the quality of the article content is high, so Xiaobian share for everyone to make a reference, I hope you have a certain understanding of related knowledge after reading this article.
Scenario: in linux system terminal, use cat to view Chinese document garbled, and use vim to view the same file without garbled. (secureCRT window code utf-8)
Use cat to view Chinese documents without garbled, the same file using vim to view garbled. (secureCRT window code is gb2312)
Analysis: The two cases are garbled separately, so it is determined that cat and vim use different decoding methods, resulting in this situation.
Workaround: change vim parse file encoding.
In vimrc, you can set encoding, fileencoding and fileencodings.
encoding: vim internal encoding method, consistent with locale by default
fileencoding: encoding method used when creating new text
fileencodings: the encoding method used when opening text, there can be multiple, decoding one by one
Changed settings:
set fileencodings=utf-8,gbk,gb2312,gb18030
set fileencoding=utf-8
set encoding=gbk
gb18030 for secureCRT windows
linux system code/etc/sysconfig/i18n LANG="zh_CN.GB18030"
If an error occurs while executing the print script, add it in the first line
#coding:utf-8
On linux system terminal cat Chinese garbled/vim not garbled or cat not garbled/vim Chinese garbled sample analysis shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.