3

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...
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
user3355020
  • 315
  • 1
  • 9

2 Answers2

5

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.

abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • You may wish to take a look at this answer as well: http://stackoverflow.com/a/5066313/324105 – phils Mar 31 '14 at 11:36
1

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))
artscan
  • 2,340
  • 15
  • 26