Emacs File Encoding FAQ

By Xah Lee. Date: . Last updated: .

This page is a tutorial on file and character encoding/decoding in emacs.

If you don't know what's encoding/decoding, see: Unicode Basics: Character Set, Encoding, UTF-8, Codepoint.

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

How to open file with specific encoding

Open it normally, then Alt+x revert-buffer-with-coding-system, then type a coding system. Press Tab to list possible ones.

How to set a encoding system for saving current file

Alt+x set-buffer-file-coding-system, then type the encoding system you want. Press Tab to see a list of possible values.

After you set a encoding system, save the file and it'll be saved in the new encoding system.

What is the encoding system used for current file

Check the value of the buffer local variable buffer-file-coding-system. [see Emacs: Show Variable Value, List Variables]

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

Emacs Line Ending

Emacs Tutorial

Quick Start


Split Window




Find Replace



Rectangle Edit

Line Wrap


View Special File

Editing Brackets

Org Mode


Emacs Efficiency