how to change encoding in gedit text editor

GEdit is one most popular text editor in Linux desktops. It comes with a whole lot of functionalities. Often times you will need to change the encoding of the file you are viewing in the editor. Many of the editors provide you with the ability to change the file encoding on the fly. We will see how we can change the encoding of files using the GEdit text editor.

One of the main features of the GEdit is that it is very simple and light weight, which means it may not have some of the features that the other text editor possess. This can be both an advantage as well as a disadvantage.

Loading the File

GEdit gives you the option to select the encoding while opening or loading the file. Start the GEdit text editor, then click on the open button in the toolbar to open a new file. This will pop up a file dialog, which will give you the option to select the character encoding of the file.


Unlike some of the other feature rich text editors such as kate, you cannot change the encoding of the file once you have loaded the file. The work around for this is to load the file again by clicking on the open button, and selecting a different character encoding in the file dialog.

By default, the selected option in the file dialog is "automatically detected". This works in most cases, and you can always change it when opening the file. However if you always want to open the file in a specific format, irrespective of what the automatic detection tells you, then this could be annoyance. You will need to remember to select the specific encoding every time. In order to get around the issue, you can change the default option of the editor using the command line.

Change Default Encoding

The gedit program provides some command line options that can be used to change the encoding used by the files. The application option to use is –encoding=ENCODING.

bash$ gedit --encoding=UTF-8 file.txt

You can save this as a shell alias, so that you can use it repeatedly with out having to retype the whole command all the time. You can also save this as executable shell script file and use that to open files by default.

gedit --encoding=UTF-16 "$@"

If you have the need to constantly change character encoding on the fly or edit different files with different encoding, then you might be better off using a more feature rich text editor instead of GEdit.