3

I'm using spacemacs on a Mac OS X laptop with a UK keyboard and I want to be able to use Alt-3 (M-3) to insert the hash symbol #. I tried to add this function that I found on this SO answer without any luck.

;; Allow hash to be entered  
(global-set-key (kbd "M-3") (lambda () (interactive) (insert "#")))

Do I have to unset this key combination before trying to set it? Is there anything else in the spacemacs configuration that always overwrite my user defined configuration with the "Change the current window with window 3"? I'm used to add the hash symbol using that combination and I feel uncomfortable using anything else.

4
  • Rather than dealing with that issue on Emacs, I added the Australian keyboard on my Mac, so # was S-3 and then didn't change anything to the Emacs config. Aug 25, 2017 at 11:09
  • I can't change my MacBook integrated keyboard. So this is not a viable solution to my problem.
    – sentenza
    Aug 25, 2017 at 13:35
  • Sorry, didn't explain myself correctly. Not the physical keyboard. You can change it on the settings panel (you can have multiple layouts and change them in the fly). There are barely differences between the uk and aus layout, so having still the uk physical keyboard is barely noticeable Aug 25, 2017 at 13:54
  • Actually as I wrote in the question itself I feel uncomfortable using something else than <kbd>Alt</kbd>-<kbd>3</kbd>, so I was looking for the correct way to configure Spacemacs to accept this custom keybinding.
    – sentenza
    Aug 25, 2017 at 14:10

2 Answers 2

6

Another approach is set (setq-default mac-right-option-modifier nil) to your dotspacemacs/user-init and start to use the "right Option+3" key to write the '#' symbol.

Definition:

(defun dotspacemacs/user-init ()
  (setq-default mac-right-option-modifier nil)
)
1
  • 1
    Cheers @Joao. This approach is working and it solved all my issues.
    – sentenza
    Aug 29, 2017 at 10:32
0

Here is the way I setup my init.el:

(global-set-key (kbd "M-3") (lambda () (interactive) (insert "#")))

(global-set-key (kbd "M-n") (lambda () (interactive) (insert "~")))

(global-set-key (kbd "M-g") (lambda () (interactive) (insert "@")))

(global-set-key (kbd "M-7") (lambda () (interactive) (insert "|")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.