gedit.preferences.encodings

問:如何解決「gedit」開啟檔案,產生中文亂碼的情形?

答:解決方法如下

python 範例

Xubuntu 16.04

執行

$ gsettings list-recursively | grep gedit | grep encodings

顯示

org.gnome.gedit.preferences.encodings candidate-encodings ['']
org.gnome.gedit.preferences.encodings candidate-encodings ['']
org.gnome.gedit.preferences.encodings candidate-encodings ['']

設定認得其他中文相關編碼

$ gsettings set org.gnome.gedit.preferences.encodings candidate-encodings "['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']"

觀看設定後的值

$ gsettings get org.gnome.gedit.preferences.encodings candidate-encodings

顯示

['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']

恢復預設值

$ gsettings reset org.gnome.gedit.preferences.encodings candidate-encodings

Xubuntu 14.04

執行

$ gsettings list-recursively | grep gedit | grep encodings

顯示

org.gnome.gedit.preferences.encodings auto-detected ['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
org.gnome.gedit.preferences.encodings shown-in-menu ['ISO-8859-15']
org.gnome.gedit.preferences.encodings auto-detected ['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
org.gnome.gedit.preferences.encodings shown-in-menu ['ISO-8859-15']
org.gnome.gedit.preferences.encodings auto-detected ['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
org.gnome.gedit.preferences.encodings shown-in-menu ['ISO-8859-15']

觀看目前的設定值

$ gsettings get org.gnome.gedit.preferences.encodings auto-detected

顯示

['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']

設定認得其他中文相關編碼

$ gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']"

觀看設定後的值

$ gsettings get org.gnome.gedit.preferences.encodings auto-detected

顯示

['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']

恢復預設值

$ gsettings reset org.gnome.gedit.preferences.encodings auto-detected

找尋相關的「schema檔」

$ grep auto-detected /usr/share/glib-2.0/schemas/org.gnome.gedit.*

顯示

/usr/share/glib-2.0/schemas/org.gnome.gedit.gschema.xml:    <key name="auto-detected" type="as">

顯示更多內容

$ grep auto-detected /usr/share/glib-2.0/schemas/org.gnome.gedit.* -A17

再次設定

$ gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']"

觀看 dconf 設定值

$ dconf dump / | grep auto-detected

顯示

auto-detected=['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']

執行

$ dconf dump / | grep gedit

顯示

[org/gnome/gedit/preferences/encodings]
[org/gnome/gedit/preferences/ui]
[org/gnome/gedit/plugins/filebrowser]
[org/gnome/gedit/plugins]
[org/gnome/gedit/state/window]

執行

$ dconf list /org/gnome/gedit/preferences/encodings/

顯示

auto-detected

執行

$ dconf read /org/gnome/gedit/preferences/encodings/auto-detected

顯示

['UTF-8', 'BIG5', 'BIG5-HKSCS', 'EUC-TW', 'GB18030', 'GB2312', 'GBK', 'CURRENT', 'ISO-8859-15', 'UTF-16']