Opening a non-utf8 encoded text file
I sometimes need to open text files that are encoded in EUC-KR.
man gedit
gives:
--encoding Set the character encoding to be used for opening the files listed on the command line.
This can be used to open specific files with the desired encoding:
gedit --encoding euc-kr readme.txt
However, each file to be opened requires a similar command to be typed.
I can run iconv
on the file(s), but then I have to deal with different file versions.
Do I have better options for dealing with non-utf8 text files?
The easiest way to specify the encoding when opening the file is to use the Open Files dialog.
On the bottom left, you will see an drop-dwon option for Character encoding. If you haven't used the encoding in Gedit before, scroll down to Add or Remove....
In the new dialog, scroll down the list of Available Encodings until you find the one you want, then click Add to send it to the list of encodings on the right, then OK.
That's it. After that you easily open the file with the correct encoding.
Nautilus Action
To have access to custom open options for Gedit from the file browser Nautilus we may define a Nautilus Action to have an entry in the right mouse click context menu which opens a selected file in Gedit with certain options. The command line for your action would then be:
/usr/bin/gedit --encoding euc-kr %b
By doing so you will be able to open files with euc-kr encoding on selecting your custom context menu entry but still be able to just double click open other files having a standard encoding.
Custom .desktop file
To be able to select Korean encoding as option in the open with dialog or as standard option we may create a custom kr-gedit.desktop
file (e.g. located in ~/.local/share/applications
) to include options in the Exec=
line. Add this custom "application" to the files properties dialog (on right click on a .txt file).
- How can I edit/create new launcher items in Unity by hand?
Alias
For the command line you may define an alias to open files with a Korean encoding. This can also be made permanent:
alias kr-gedit="gedit --encoding euc-kr"
Add auto detected charset in file: ~/.gconf/apps/gedit-2/preferences/encodings/%gconf.xml
<?xml version="1.0"?>
<gconf>
<entry name="auto_detected" mtime="1444988803" type="list" ltype="string">
<li type="string">
<stringvalue>UTF-8</stringvalue>
<stringvalue>WINDOWS-1251</stringvalue>
<stringvalue>UTF-16</stringvalue>
</li>
</entry>
<entry name="shown_in_menu" mtime="1444988803" type="list" ltype="string">
<li type="string">
<stringvalue>WINDOWS-1251</stringvalue>
</li>
</entry>
</gconf>
Here the line "<stringvalue>***</stringvalue>" - the desired cahrsets