Emacs: Unicode Tutorial

By Xah Lee. Date: . Last updated: .
emacs unicode 2018 03 18 53969
emacs showing Unicode chars. You can download this text here: unicode.txt.

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 lists 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 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 then type “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)

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: insert-char was ucs-insert in emacs 24.3 or before.

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 insert-charCtrl+x 8 Enter】, then type “#10r” followed by the decimal codepoint. e.g. #10r8594

For example, try insert . Its coidpoint in decimal is “8594”.

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 Setup.

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. Unicode Tutorial
  2. Emacs File Encoding FAQ
  3. Unicode Basics: What's Character Set, Character Encoding, UTF-8?
  4. Xah Math Input Mode
  5. Xah Unicode Browser Mode

  1. Best Unicode Fonts for Programer
  2. Font Setup
  3. Proportional Font
  4. Cycle Fonts by Command
  5. Set Line Spacing
  6. 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.