Search code examples
emacsunicodekeystroke

Key binding for § symbol in Emacs


I'm working in Ubuntu, but since the standard way of inserting unicode characters (Ctrl+Shift+U and, after that, the unicode code) doesn't work inside emacs, I've, in my .emacs, some keystrokes for different unicode symbols which I use frequently, for example:

(global-set-key (kbd "C-c b") "☛")

and every symbol works fine, except the symbol §, which is replaced by a simple dash ("-") when I use the corresponding keystroke:

(global-set-key (kbd "C-c y") "§")

The question is, what does it make this symbol different for other symbols and how can I solve my problem?


Solution

  • global-set-key usually expects a function, so this should work:

    (global-set-key (kbd "C-c y") (lambda () (interactive) (insert "§")))
    

    But you're better off using the excellent insert-char function:

    (global-set-key (kbd "<f2> u") 'insert-char)
    

    It understands hex Unicode as well as text description (with completion and all). Just press TAB to see the completions.