Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs question - hash key

Tags:

emacs

macos

I have a Mac Laptop and I am connecting to server running Linux. As Alt+3 is already bound in EMACS to a command, so I cannot insert the hash symbol in a file. I have tried the following solution I found online:

(global-unset-key (kbd "C-3")) (global-set-key (kbd "C-3") '(lambda() (interactive) (insert-string "#")))      //I know that C is for CTRL not Alt - I have tried with M-3 instead as well 

and some others as well, but none seem to work. Can you tell me any other way in which I might be able to enter the hash sign (#) in a file.

Aso tried (did not work):

(fset 'insertPound "#") (global-set-key (kbd "M-3") 'insertPound) 

Thank you!

like image 778
Andrei Avatar asked Oct 20 '10 11:10

Andrei


1 Answers

From http://jimbarritt.com/non-random/2010/11/07/typing-the-pound-or-hash-key-in-emacs-on-uk-macbook

Typing the pound, or hash (#) key in emacs on UK Macbook:

The problem with OS X and the UK keyboard is that the pound key actually has a £ on it. To get “#” you have to press Alt+3

Of course, in emacs, the alt key is the meta key which is trapped by emacs. The simple function below inserted into your .emacs file should map the keys correctly.

;; Allow hash to be entered   (global-set-key (kbd "M-3") '(lambda () (interactive) (insert "#"))) 
like image 59
Nick Crabtree Avatar answered Oct 22 '22 17:10

Nick Crabtree