Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 516
Jan Deinhard Avatar asked Jun 20 '12 19:06

Jan Deinhard


People also ask

How do I type a tilde symbol on a Mac?

That is on the left side of Enter and below the Backspace key. When pressing Alt ^¨ and space the tilde ~ appears.

How do I type a tilde?

iOS or Android device: Press and hold the A, N, or O key on the virtual keyboard, then select the tilde option.


2 Answers

While this question is pretty old, none of the answers seems satisfying for Emacs for OS X (the most popular choice these days). So, for future readers ...

Plain Emacs for OS X uses both Alt keys as Meta by default. As many characters are typed using Alt on a german Mac keyboard (tilde, brackets, curly braces etc.), I'd recommend setting ns-right-alternate-modifier to nil, which enables typing tilde (Alt-n) and other characters using the right Alt key, while the left one can be used as Meta (like for M-x).

Alternatively Cmd can be customized to be Meta. All options can be interactively customized under M-x customize-group ns.

like image 134
fpbhb Avatar answered Sep 28 '22 18:09

fpbhb


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.

like image 21
GoZoner Avatar answered Sep 28 '22 18:09

GoZoner