Emacs: File Encoding

By Xah Lee. Date: . Last updated: .

What is Character Encoding

Set default encoding system for opening and saving, globally

How to 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

How to 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.

How to set a encoding system 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


A Buffer Local Variable . Value is the character coding system for current buffer. [see Emacs: Show Variable Value]

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)

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


Emacs and Unicode

File Encoding

Unicode Font Setup

Emacs Line Ending