Emacs: File Encoding (Unicode, UTF-8)

By Xah Lee. Date: . Last updated: .

What is Character Encoding

Set default encoding for read and write file, globally

Declare a file with a specific encoding

List emacs file encoding systems

Alt+x list-coding-systems

Show a list of all coding systems.

emacs 29 list-coding-systems 2023-08-30
emacs 29 list-coding-systems 2023-08-30

Open file with specific encoding

Alt+x revert-buffer-with-coding-system

Refresh current buffer using a specific coding system to decode the file.

Press Tab to list possible ones.

Set a encoding for saving current file

Alt+x set-buffer-file-coding-system

Set the file coding-system of the current buffer. (do a file save to save it with the new coding-system.)

Press Tab to see a list of possible values.

What is the encoding system used for current file

buffer-file-coding-system

A Buffer Local Variable . Value is the character coding system for current buffer. 〔see Emacs: Show Variable Value and Doc

Set Encoding for Terminal output

This is important especially on Microsoft Windows. If you don't set this to utf-8, you may have problems with Python output of Unicode string.

Alt+x set-terminal-coding-system

put this in your Emacs Init File:

(set-terminal-coding-system 'utf-8-unix)

default-terminal-coding-system

Set Encoding for Keyboard Input

Alt+x set-keyboard-coding-system

put this in your Emacs Init File:

(set-keyboard-coding-system 'utf-8-unix)

View Current Coding System Config

Alt+x describe-current-coding-system
emacs describe-coding-system 2022-10-10
emacs describe-coding-system 2022-10-10

View Emacs Doc of a Specific Coding System

Alt+x describe-coding-system

Reference

Emacs and Unicode

File Encoding

Unicode Font Setup

Emacs Line Ending