Emacs: Unicode Tutorial

emacs showing Unicode chars. You can download this text here: unicode.txt.

Set default file encoding Put this in your emacs init file: (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: Emacs File Encoding FAQ

Unicode Basics

Set a key to insert unicode char For example, put the following code in your emacs init file. ( 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 Search 😄

Use abbrev to insert Unicode char Put the following in your emacs init file: ( define-abbrev-table ' global-abbrev-table '( ( "alpha" "α" ) ( "inf" "∞" ) ( "ar" "→" ) )) (abbrev-mode 1) 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 by Commands. If you type math symbols often, use Emacs: Xah Math Input Mode.

Insert letter with accent marks é é → 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)

Insert a Unicode character by name Alt + x insert-char 【 Ctrl + 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.

Insert a Unicode character by its hexadecimal value Alt + x insert-char 【 Ctrl + x 8 Enter 】, then the hex of the Unicode. For example, try insert → . Its hex value is “2192”.

Insert a Unicode character by its decimal value Alt + x insert-char 【 Ctrl + 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.

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-method 【 Ctrl + \ 】. For detail, see: Emacs Chinese Input.

Find out current input method Alt + x describe-variable 【 Ctrl + h v 】 then type current-input-method .

Find a character's hex value or name Place cursor on the character then call describe-char . M-x describe-char For a mode to make this easier, see xub Unicode Browser mode for Emacs.

Update emacs unicode data database Unicode has a new version every year. Emacs's unicode info for describe-char may not be up-to-date. (it doesn't know the new character). You can make emacs use the latest unicode data. Download the latest UnicodeData.txt at https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt Put that file in your emacs init dir. Put this in your emacs init file: ( when ( file-exists-p "~/.emacs.d/UnicodeData.txt" ) ( setq describe-char-unicodedata-file "~/.emacs.d/UnicodeData.txt" ))

Get emacs to display missing emoji 😸 See: Emacs: Font Setup.

Unicode Characters Search

Unicode Search 😄