This page is a tutorial on using emacs and Unicode. ⁖ how to type math symbol, how to switch input methods, finding Unicode character name or code point, how to set file encoding, ….
This page covers emacs 23 or later. You should use emacs 23 (released in 2009) or later, because emacs 23 has major update of its character engine. 〔➤ New Features in Emacs 23〕
How to type this character é ?
Here's a table on how to type these chars:
|é||【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.
How to insert a Unicode character by name?
insert-char 【Ctrl+x 8 Enter ↵】, then the name of the Unicode. For example, try insert “λ”. Its name is “GREEK SMALL LETTER LAMDA”.
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: before emacs 24, you need to call
ucs-insert instead of
ucs-insert is obsolete since 24.3.
How to insert a Unicode character by its hexadecimal value?
insert-char 【Ctrl+x 8 Enter ↵】, then the hex of the Unicode. For example, try insert “λ”. Its hex value is “3bb”.
How to insert a Unicode character by its decimal value?
eval-expression, then type
How to open a Unicode character palette?
You can put frequently used Unicode chars into a file and save it, and define a keystroke to open this file, so that you can copy ＆ paste the chars you want. Here's how you can define a keystroke to open a file. Put the following in your emacs init file.
; open my Unicode template with F8 key (global-set-key (kbd "<f8>") (lambda () (interactive) (find-file "~/emacs.d/my_unicode_template.txt")))
Here's a example of a template: unicode.txt.
How to set a keystroke to insert a Unicode char?
For example, put the following code in your emacs init file.
(global-set-key (kbd "<f9> a") (lambda () (interactive) (insert "α"))) ; F9 followed by a (global-set-key (kbd "<f9> b") (lambda () (interactive) (insert "β")))
Alternatively, you can use key-translation-map. For detail, see: Emacs: Remapping Keys Using key-translation-map. For OS-wide, see: How to Create a APL or Math Symbols Keyboard Layout.
How to use abbrev to input Unicode chars?
Put the following in your emacs init file:
(define-abbrev-table 'global-abbrev-table '( ("alpha" "α") ("beta" "β") ("gamma" "γ") ("theta" "θ") ("inf" "∞") ("ar1" "→") ("ar2" "⇒") )) (abbrev-mode 1) ; turn on abbrev mode
Select the code above and call
alpha , it will become “α ”.
If you type math symbols often, buy my Emacs: xah-math-input.el.
How to type Chinese?
set-input-method 【Ctrl+x Enter ↵ Ctrl+\】, then give value
chinese-py. (“chinese-py” is a basic Chinese pinyin input method.)
Then, you can start typing Chinese. For detail, see: Emacs Chinese Input for Studying Chinese.
To switch back, call
How to find out what's the current input method?
describe-variable 【F1 v】 then type current-input-method.
I have this character α on the screen. How to find out its Unicode's hex value or name?
You can find out a char's info by placing your cursor on the character then call
Following is the output of
describe-char on char “α” in Emacs 24:
position: 9878 of 14133 (70%), column: 82 character: α (displayed as α) (codepoint 945, #o1661, #x3b1) preferred charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF)) code point in charset: 0x03B1 syntax: w which means: word category: .:Base, G:2-byte Greek, L:Left-to-right (strong), c:Chinese, g:Greek, h:Korean, j:Japanese to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME" buffer code: #xCE #xB1 file code: #xCE #xB1 (encoded by coding system utf-8-unix) display: by this font (glyph code) xft:-unknown-DejaVu Sans Mono-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1 (#x2F7) Character code properties: customize what to show name: GREEK SMALL LETTER ALPHA general-category: Ll (Letter, Lowercase) decomposition: (945) ('α') There are text properties here: face xah-html-curly“”-quoted-text-face fontified t
Unicode version 6 (released in 2010-10) added about 1k more symbols. Emacs 23.2 does not have info on these new symbols. (⁖ 😸 GRINNING CAT FACE WITH SMILING EYES) 〔➤ Unicode 6 Emoticons〕
You can get these info by downloading a Unicode data file and let emacs know where it is. Download it at: http://www.unicode.org/Public/UNIDATA/UnicodeData.txt, then, place the following code in your “.emacs”.
;; set Unicode data file location. (used by what-cursor-position and describe-char) (let ((x "~/emacs.d/UnicodeData.txt")) (when (file-exists-p x) (setq describe-char-unicodedata-file x)))
Select the above code, then call
eval-region. Then, you will have full Unicode char info when calling
See also: xub Unicode Browser mode for Emacs.
How to get emacs to display some Unicode emoticon?
Emacs File/Character Encoding/Decoding FAQ
Emacs Lisp: Unicode Representation in String
Unicode Characters Search ☢ ☯ ☭ ∑ ∞ ♀ ♂ ♥