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: What's Character Set, Character Encoding, UTF-8?.

How to open a file with specific coding system?

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 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, you can save the file and it'll be saved in the new encoding system.

In a buffer, how to find out what encoding system was used to decode current file?

Check the value of the variable buffer-file-coding-system. You do that by Alt+x describe-variableCtrl+h v】.

emacs describe-coding-system
emacs describe-coding-system

How to find out what's the current coding system used for opening and saving files?

Alt+x describe-coding-system

How to permanently choose a encoding system in emacs for opening and saving?

Put this in your emacs init file:

;; UTF-8 as default encoding
(set-language-environment "UTF-8")

What encoding systems emacs supports?

Alt+x list-coding-systems

Is there a way to declare a file with a particular character encoding?

Yes. In the first line of your file, put -*- coding: utf-8 -*-. That way, each time emacs open the file, emacs will presume that the file is encoded in utf-8. The line can start with a comment character(s) of your language, such as “#”, “//”. This magic line is also adopted by Python.

(info "(emacs) File Variables")

Where can one read more about Unicode in emacs?

Unicode Basics: What's Character Set, Character Encoding, UTF-8?

(info "(emacs) International")

Font/Unicode Topic

  1. Emacs: Unicode Tutorial
  2. Emacs File Encoding FAQ
  3. Unicode Basics: What's Character Set, Character Encoding, UTF-8?
  4. Emacs: Xah Math Input Mode
  5. Emacs: Xah Unicode Browser Mode

  1. Best Unicode Fonts for Programer
  2. Emacs: Font Setup
  3. Emacs: Proportional Font
  4. Emacs: Cycle Fonts by Command
  5. Emacs: Set Line Spacing
  6. Emacs: toggle-word-wrap
  7. Elisp: Unicode Representation in String
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.