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, Alt+x switch-to-buffer to “*Completions*”.

Alt+x 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 Alt+x 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, Alt+x 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?

Alt+x 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, Alt+x 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?

Alt+x 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?

Alt+x 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?

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

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

For detail, see: Emacs Chinese Input.

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

Alt+x 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

Elisp: Unicode Representation in String

Elisp: 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: Proportional Font
  4. Emacs: Cycle Fonts by Command
  5. Emacs: Set Line Spacing
  6. Emacs: toggle-word-wrap
  7. Elisp: Unicode Representation in String
Liket it? Put $1 at patreon. Or Buy Xah Emacs Tutorial. Thanks.