Home  >  Article  >  System Tutorial  >  Methods to solve the Chinese garbled problem of vim in Linux server and introduction of related parameters

Methods to solve the Chinese garbled problem of vim in Linux server and introduction of related parameters

WBOY
WBOYOriginal
2024-06-01 21:20:24622browse

linux中字符乱码解决方法介绍

Remotely logging into the Linux server and using vim to edit and view files in the terminal often encounters various English garbled problems.

The following settings can basically solve the vim English garbled problem

First check the system’s support for English

locale-a|grepzh_CN

The output sample is as follows

zh_CN.gbk

乱码怎么写_乱码复制_linux rz 乱码

zh_CN.utf8

vim can only correctly recognize English-encoded files in the list. If you need to recognize English files of other encoding types, you need to upgrade the system

vi~/.bash_profile

Add

at the end of the file

exportLANG="zh_CN.UTF-8"

乱码怎么写_乱码复制_linux rz 乱码

exportLC_ALL="zh_CN.UTF-8"

Online video tutorial recommendation: linux video tutorial

Vim 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 usually not used

2. Fileencodings, as you can see from the name, is an improved version of fileencoding. You can configure deepin linux 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 For vim to read correctly, it is recommended to configure: setfileencodings=utf-bom,utf-8,gbk,gb2312,gb18030,cp936,latin1

3. Encoding, vim internal encoding, after vim reads the file, it does not process the encoding of the read file linux rz garbled code, but will convert it into the internal encoding format, this encoding It is usually related to the operating system. Most of them are utf-8 under Linux, and gdk under English windows. It is recommended to configure: setencoding=utf-8

4. termencoding, the encoding of vim output. Output refers to output to the operating system or command terminal. 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 vim will not take care of shelllinux home. However, if the shell does not have an English name file, just configure the terminal and termencoding to be consistent. For windows, gbk and utf-8 can be manually identified without special Configuration, recommended configuration: settermencoding=utf-8

5. Fileformats, used to distinguish the operating system, mainly the difference between carriage return rnlinux rz garbled code, recommended configuration: setfileformats=unix,dos

Common garbled characters include the following situations:

(1) When rz files from windows environment to linux, the files appear garbled

乱码复制_乱码怎么写_linux rz 乱码

solution:

1. Use notepad++ to convert the file format to UTF-8 BOM-free format or ANSI encoding format before rz;

2.setencoding=utf-8;

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

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

乱码复制_乱码怎么写_linux rz 乱码

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

(4)wget download file name is garbled

Solution: Usually add –restrict-file-names=nocontrol, such as wget--restrict-file-names=nocontrol-m

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

Solution: Write directly to /etc/vim/vimrc, add

to the last line

setfileencodings=gb2312,utf-8

setfileencoding=gb2312

settermencoding=utf-8

The above is the detailed content of Methods to solve the Chinese garbled problem of vim in Linux server and introduction of related parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn