Emacs: Unicode Tutorial

By Xah Lee. Date: . Last updated: .
Carbon emacs 22 Unicode
A screenshot of emacs window showing Unicode chars. You can download this text here: unicode.txt. (not exactly the same)

How to set default file encoding?

Put this in your emacs init:

(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

To find possible valid values, type Alt+x set-language-environment, then press Tab ↹ to show all possible valid values. Press Ctrl+g to cancel. Then, call switch-to-buffer to “*Completions*”.

Call list-coding-systems to see possible valid values.

See also:

Insert Unicode Characters

How to set a key to insert unicode char?

For example, put the following code in your emacs init file.

;; set keys to insert math symbol
(define-key key-translation-map (kbd "<f9> p") (kbd "φ"))
(define-key key-translation-map (kbd "<f9> x") (kbd "ξ"))
(define-key key-translation-map (kbd "<f9> i") (kbd "∞"))
(define-key key-translation-map (kbd "<f9> <right>") (kbd "→"))

For detail, see: Emacs: Remapping Keys Using key-translation-map.

For OS-wide, see: How to Create a APL or Math Symbols Keyboard Layout.

For list of math symbols and Unicode search, see Unicode Characters ☯ ☭ ⚡ ∑ ♀ ♂ ♥ 😄

How to use abbrev to input Unicode chars?

Put the following in your emacs init file:

(define-abbrev-table 'global-abbrev-table '(
    ("alpha" "α")
    ("inf" "∞")
    ("ar" "→")

(abbrev-mode 1) ; turn on abbrev mode

Select the code above and call eval-region. 〔➤see How to Evaluate Emacs Lisp Code

Now, type ar , it will become .

For detail, see: Emacs: Abbrev Mode Tutorial.

If you type math symbols often, use Emacs: Xah Math Input Mode.

How to type letters with accent marks? e.g. é?

CharacterKey Press
éCtrl+x 8 ' e
àCtrl+x 8 ` a
îCtrl+x 8 ^ i
ñCtrl+x 8 ~ n
üCtrl+x 8 " u

To see all characters you can type this way, press 【Ctrl+x 8 Ctrl+h】. Example: ¿ ¡ ¢ £ ¥ ¤ § ¶ ® © ª «» × ÷ ¬ ° ± µ ÀÁÂÃÄÅÆ Ç ÈÉÊË ÌÍÎÏ ÐÑ ÒÓÔÕÖ ØÙÚÛÜÝÞß àáâãäåæç èéêë ìíîï ðñòóôõö øùúûüýþÿ.

If you need to type these chars often, call set-input-method and give “latin-9-prefix”. That will allow you to type these chars without typing 【Ctrl+x 8】 first.

(Emacs's “latin-9-prefix” corresponds to the char set ISO 8859-9)

A better way is to install Emacs: Xah Math Input Mode. With that, to type é, just type e' followed by a activation key.

How to insert a Unicode character by name?

Call insert-charCtrl+x 8 Enter ↵】, then the name of the Unicode. For example, try insert . Its name is “RIGHTWARDS ARROW”.

You can use asterisk * to match chars. For example, call insert-char, then type *arrow then Tab ↹, then emacs will show all chars with “arrow” in their names.

Note: in emacs 24, ucs-insert is renamed to insert-char. ucs-insert is obsolete since 24.3.

How to insert a Unicode character by its hexadecimal value?

Call insert-charCtrl+x 8 Enter ↵】, then the hex of the Unicode. For example, try insert . Its hex value is “2192”.

How to insert a Unicode character by its decimal value?

Call eval-expression, then type (insert-char 8594) for .

A more convenient way is to install Emacs: Xah Math Input Mode.

Typing Chinese or Non-Latin Languages

How to type Chinese?

Call set-input-method, then give value chinese-py. (“chinese-py” is a basic Chinese pinyin input method.)

To switch back to normal input, call toggle-input-methodCtrl+\】.

For detail, see: Emacs Chinese Input for Studying Chinese.

How to find out what's the current input method?

Call describe-variableCtrl+h v】 then type current-input-method.

Find Character Info

How to find out a Unicode's hex value or name?

Place cursor on the character then call describe-char.

emacs find unicode info describe-char 2015-09-20
M-x describe-char

For a mode to make this easier, see xub Unicode Browser mode for Emacs.

How to get emacs to display missing emoji 😸?

See: Emacs: Font Configuration.

Emacs File Encoding FAQ

Emacs File Encoding FAQ

Emacs Lisp: Unicode Representation in String

Emacs Lisp: Unicode Representation in String

More About Unicode

Unicode Characters Search

Unicode Characters ☯ ☭ ⚡ ∑ ♀ ♂ ♥ 😄

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 Configuration
  3. Emacs: Set Font by Major Mode, Switch Fonts by Command
  4. Emacs: Set Line Spacing
  5. Emacs: toggle-word-wrap
  6. Emacs Lisp: Unicode Representation in String
Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs