Search code examples
macosemacskey-bindingsaquamacs

How to write a tilde (~) character in Emacs on Mac OS X?


I'm used to write a ~ character by pressing Alt+N on Mac OS X. This does not work in Emacs. Alt+N key seems to be bind to the command history. So my question is how to write a ~ character in Emacs on Mac OS X?

EDIT: I'm using Aquamacs.


Solution

  • You could always open the 'character viewer', select 'Punctuation', find '~' (tilde), and then double click it. That will insert it at the Emacs point. (The 'character viewer' is readily accessible after checking 'Show Keyboard & Character Viewers in menu bar' from the Keyboard pane in the System Preferences window.)

    You could also define an emacs-lisp function as:

    (defun tilde () (interactive) (insert "~"))
    

    and then invoke it with M-x tilde to insert a tilde. Could then assign that function to the key combo of your choice as

    (global-set-key "\M-\C-!" 'tilde)   ;; you choose the combo
    

    and add all this to your 'emacs init' file.