Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Rebind numbers (Editor of the Beast VI VI VI)

Just coming to Emacs from vi.

I'd like to rebind all the numbers across the top of the keyboard to their shifted counterparts (i.e. 1 maps to !, 2 maps to @, etc), while at the same time keeping the numerical keypad numbers as simply numbers.

I remapped the numbers just fine, and the numbers across the top of the keyboard map to symbols correctly; however this also maps the keypad numbers to symbols. In response I tried to remap the keypad numbers back to numbers again but this is unsuccessful - they stay as symbols.

This was straightforward and easy to accomplish when I was using vi, but I would prefer to keep using Emacs. Anyone have a solution?

Sample .emacs:

(global-set-key "1" "!")
; etc...

(global-set-key [kp-1] "1")
; etc...
like image 497
user3355020 Avatar asked Dec 14 '25 01:12

user3355020


2 Answers

Maybe something like this:

(global-set-key (kbd "<kp-1>") "1")
(keyboard-translate ?1 ?!)

I would actually use xmodmap to change the keys across the whole system, not just Emacs.

like image 156
abo-abo Avatar answered Dec 16 '25 23:12

abo-abo


Try this:

(global-set-key "1" "!")
(global-set-key [kp-1] (lambda () (interactive) (insert "1")))

P.S. I use (lambda () (interactive) ...) in global-set-key frequently and create alias for it:

(defmacro ilam (&rest body)
  "Interactive lambda"
  `(lambda ()
     (interactive)
     ,@body))
like image 45
artscan Avatar answered Dec 16 '25 22:12

artscan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!