
Linux系统vim查看文件中文乱码
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
1、背景
服务器部署业务过程中查看文件内容,使用cat
命令查看中文正常显示,使用vim
命令查看显示中文乱码
cat 查看
vim 查看
2、环境
名称 | 版本 |
---|---|
操作系统 | CentOS Linux release 7.6.1810 (Core) |
登陆协议 | OpenSSH_7.4 |
vim | 74 |
cat | 8.22 |
xshell | 7 |
3、目的
vim 查看文件和cat查看文件过程中中文正常显示
4、原因
vim 编码原因导致
5、操作步骤
5.1、修改vim编码配置
1、查找配置文件
vim 配置文件为vimrc文件,通过如下命令找到vimrc文件路径
whereis vimrc
vimrc: /etc/vimrc /usr/share/man/man5/vimrc.5.gz
2、备份配置文件
备份文件
cp /etc/vimrc{,.bak}
3、修改配置文件
vim /etc/vimrc
文件末尾追加如下信息
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
说明:
encoding: 该配置用于设置缓冲的文本(你正在编辑的文件),寄存器,Vim 脚本文件等采用的编码。
fileencoding: 该配置用于设计vim写入文件时采用的编码类型。
termencoding: 该配置用于系统将文件内容输出到客户终端(Term)采用的编码类型。
6、验证
验证操作是否达到预期的目的,再次使用vim命令查看该文件
vim /etc/vimrc




A beautiful web dashboard for Linux
最近提交(Master分支:5 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
所有评论(0)