gedit打开文件显示中文乱码

一、 gedit打开文件显示中文乱码的解决方法(先查看gedit版本)
Gedit 2.x版本设置(适用于Ubuntu 11.04及以前)
安装gconf-editor: sudo apt-get install gconf-editor
方式1:启动gconf-editor
在弹出的配置中选择:“apps”—“gedit2”—“preferences”—“encodings”。双击右边名称“auto- detected”,在弹出的编辑键菜单中,添加编码GB18030,GBK,GB2312,移到最上面即可
方式2:命令行方式
gconftool-2 --set --type=list --list-type=string /apps/gedit-2/preferences/encodings/auto_detected
"[UTF-8,CURRENT,GB18030,ISO-8859-15,UTF-16]"

Gedit 3.x版本设置(适用于Ubuntu 11.10及以后)
安装dconf-editor: sudo apt-get install dconf-tools
方式一:启动dconf-editor   在org/gnome/gedit/preferences/encodings下添加中文编码方式
方式二:命令行方式
gsettings set org.gnome.gedit.preferences.encodings auto-detected "['GB18030', 'UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']"
有的版本可能键值是candidate-encodings,则用下面命令
gsettings set org.gnome.gedit.preferences.encodings candidate-encodings "['GB18030', 'UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']"
二. ubuntu添加中文字符编码的方法
1. 使用如下命令查看系统支持的字符集
cat /usr/share/i18n/SUPPORTED
说明:查看系统支持的字符集,你需要注意的是支持字符集的格式,如对中文会有以下一些显示(不同系统可能有不同值)
zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
zh_CN GB2312
2.命令:sudo vim /var/lib/locales/supported.d/local
说明:打开系统字符集配置文件,将支持的中文字符集添加进去,格式如1中得到所示。
3.命令:sudo locale-gen
说明:更新。
三、临时解决方法,将GBK编码的文档用UTF-8格式在终端显示出来
iconv -f GBK -t UTF-8 x.txt
x.txt为要查看的文件,然后就可以在终端看到正常的文件了
iconv -f GBK -t UTF-8 x.txt >xx.txt
此条命令可以把转换后的内容存入xx.txt

你可能感兴趣的:(gedit打开文件显示中文乱码)